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

fix: prevents duplicated shortcut's callback immediate execution #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gthau
Copy link

@gthau gthau commented Mar 12, 2025

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines: CONTRIBUTING.md#commit
  • Tests for the changes have been added (for bug fixes / features)x
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Current behavior: when registering a duplicated shortcut, the observable returned by the duplicate shortcut registration immediately emits null on subscribe, resulting in the shortcut's callback being executed immediately even though the shortcut wasn't triggered.

Issue Number: 72

What is the new behavior?

The observable returned by the duplicated shortcut's registration is EMPTY, it never emits and completes immediately. This fixes the issue.

Does this PR introduce a breaking change?

[x] Yes
[] No

If a consumer relies on the observable emitting null to detect duplicate shortcuts and trigger custom logic, then this change is breaking.
It can be mitigated though: since rxjs EMPTY is a constant, one can check equality of the value returned by addShortcut and addSequenceShortcut to detect duplicated shortcuts:

  const shortcutObs = this.hotkeysService.addShortcut({ keys: 'control.c' });
  if (shortcutObs === EMPTY) {
     // custom logic for duplicate shortcut
  }

Other information

closes #72

Copy link

stackblitz bot commented Mar 12, 2025

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@gthau gthau force-pushed the bugfix/issue-72-duplicate-shortcut-trigger-shortcut-callback branch from f70e412 to b8fd994 Compare March 12, 2025 20:15
@NetanelBasal
Copy link
Member

@gthau can you please fix ci?

…ring of duplicated shortcuts

When registering a duplicated shortcut, the `addShortcut` and
`addSequenceShortcut` methods return `of(null)` which immediately emits on
subscribe. In case of duplicated shortcuts, we instead return EMPTY which
doesn't emit and completes immediately on subscribe.
@gthau gthau force-pushed the bugfix/issue-72-duplicate-shortcut-trigger-shortcut-callback branch from b8fd994 to 6dc1278 Compare March 13, 2025 15:33
@gthau
Copy link
Author

gthau commented Mar 13, 2025

@gthau can you please fix ci?

Hi @NetanelBasal ,
I had a look at the CI failure. It is not related to my changes, but to a deprecation of the @actions/cache package used in the pipeline as of March 1st, see https://github.blog/changelog/2024-12-05-notice-of-upcoming-releases-and-breaking-changes-for-github-actions/#actions-cache-v1-v2-and-actions-toolkit-cache-package-closing-down

As I'm not familiar with Github's pipeline configuration, could you please tell me which version of the actions/cache to use? Github suggests using either v3 or v4. Which one do you want me to update the pipeline with? https://github.com/ngneat/hotkeys/blob/master/.github/workflows/test.yml#L23
image

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.

Misleading return value when registering duplicate value
2 participants