Skip to content
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

add transformers api #20

Merged
merged 11 commits into from
Apr 4, 2024
Merged

add transformers api #20

merged 11 commits into from
Apr 4, 2024

Conversation

myandrienko
Copy link
Contributor

Continuing from this comment: #15 (comment)

Implementing the transformers API and switching overrides to transformers.

README.md Outdated
@@ -61,14 +61,15 @@ import {
hotkeyKeyUX,
jumpKeyUX,
focusGroupKeyUX,
overrides,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s add second word to the name to avoid possible conflict with user code.

Like overrideshotkeyOverrides

index.d.ts Outdated
* getHotKeyHint(window, 'b', [hintOverrides(config)]) // Alt + B
* ```
*/
export function hintOverrides(config: HotkeyOverride): Transformer
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is very easy to user to send overrides instead of hintOverrides.

One solution is to add protection with types adding 2 different Transformer types.

Another option is to make transformers both-way. I like this idea because seems like we will need hotkey/hint versions of transformer for every transformer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's go with both-way transformers.

@myandrienko myandrienko requested a review from ai April 4, 2024 14:39
index.d.ts Outdated
@@ -38,6 +38,10 @@ export interface FocusGroupKeyUXOptions {

export type HotkeyOverride = Record<string, string>

export interface Transformer {
(code: string, window: MinimalWindow, dir?: 'r'): false | string
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like dir: 'r' code is completely different from normal one.

Maybe we should not use the single function, but have 2?

export type Transformer = [
  (code: string, window: MinimalWindow): false | string,
  (code: string, window: MinimalWindow): false | string
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Mac compatibility transformer from #15 the code will be more similar at will benefit from having a single function. So it's a trade-off.

But aesthetically I prefer two functions.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, let’s use argument. What do you think if we call it reverse: boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried both approaches, and in terms of compressed size two functions have a slight advantage. Since it's also aesthetically nicer, let's go that way? I updated the PR.

@myandrienko myandrienko requested a review from ai April 4, 2024 15:08
@ai ai merged commit 5713cff into ai:main Apr 4, 2024
4 checks passed
@ai
Copy link
Owner

ai commented Apr 4, 2024

Looks great. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants