-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API alterations to allow injection of hotkey parsing and event processing #69
Comments
I think this is a great plan going forward and I've added it to the v2 tracking issue #65! One quibble I'd make with this API though is around the naming of
Notice that these names align with the function argument names you have already proposed. I also wonder if we want to use a class approach: One concern I have with the class approach is that I would expect that state would be managed in the class instance, but we currently manage state in module-scoped private variables. I think we could continue with a functional approach, but pass a config object to the The API, then could be export type ProcessHotkey = (hotkey: string): string[][]
export type ProcessEvent = (event: KeyboardEvent): string
export interface HotkeyOptions {
hotkey?: string;
processHotkey: ProcessHotkey;
processEvent: ProcessEvent;
}
export function install(
element: HTMLelement,
options = {
hotkey,
processHotkey: expandHotkeyToEdges,
processEvent: eventToHotkeyString;
}: HotkeyOptions
): void {}
export function uninstall(element: HTMLElement): void {} This would almost not even be a breaking change — except I had to move the optional Anyways, I am okay with either approach in the end: just thought I would throw this option out there. |
Your suggestion here LGTM 👍
The problem with that proposal is less to do with |
Yeah! I totally agree with this. I am onboard with the class. |
(I updated the code in your description with the changed processor names) |
I think a useful migration strategy would be to allow serialization/comparison to be overridden as part of the API.
When we talk about what this library does that is "novel" (as in, something you cannot reasonably achieve in a few LOC locally) the library does three things:
install
/uninstall
API to simplify adding/removing event listeners and state from the Radix Trie.The last one is what causes us a lot of trouble and causes some trashing in this library.
radix-trie.ts
hasn't been touched in 9 months, prior to that 2 years ago. I'd sayradix-trie
is "feature complete". Meanwhilehotkey.ts
has a regular cadence of alterations every few months as we reach edge cases and scale our use of this library.The chief problems with the serialization format are:
WSAD
) vs "Semiotic" (?
) shortcuts.Effectively the serialization of these shortcuts is, what you might call, unsolved. So I say let's make that apparent by allowing it to be overridden in the API.
The current API is as follows:
I propose we expand this to the following:
By making a class, we can define custom processing for shortcut keys which allows users to define their own shortcut models, but also allows us to make more breaking changes behind experimental APIs, and even feature flag them. By still exposing the
install
/uninstall
functions per the existing API, we ensure backwards compatibility which minimizes breaking changes, and allows us to "make the hard change easy then make the easy change". A 2.0 change could effectively swap the default hotkey functions out for the newer API, as a one line change.Thoughts @github/ui-frameworks?
The text was updated successfully, but these errors were encountered: