ngneat/hotkeys

Misleading return value when registering duplicate value

fynnfeldpausch opened this issue · 1 comments

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

If a duplicate shortcut is registered, the library logs an error to the console and resolves with an observable holding null (https://github.com/ngneat/hotkeys/blob/master/projects/ngneat/hotkeys/src/lib/hotkeys.service.ts#L160). This leads to unexpected behaviour, because the callback to execute when the shortcut has been pressed, is still executed but the event is null. This becomes especially confusing, because of the of(null) the callback is immediately executed, even if the key has not been pressed.

Expected behavior

The observable should error, if an error occurs, thus not executing the callback.

Minimal reproduction of the problem with instructions

Just register a callback twice.

Environment


Angular version: 15.x

Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX

You're welcome to create a PR.