omridevk / ng-keyboard-shortcuts

Dead Simple Keyboard Shortcuts Management for Angular
https://ng-keyboard-shortcuts.vercel.app/
147 stars 34 forks source link

add the KeyboardShortcutsService to the exported API #67

Closed thoussem closed 4 years ago

thoussem commented 4 years ago

Is your feature request related to a problem? Please describe. I have to add the 'ng-keyboard-shortcuts' component every time i want to subscribe to a shortcut:

<ng-keyboard-shortcuts></ng-keyboard-shortcuts>
-----
@ViewChild(KeyboardShortcutsComponent, { static: false })
private keyboard: KeyboardShortcutsComponent;
-----
this.keyboard.select('del').subscribe(_ => {
   // do something
});

Describe the solution you'd like Inject directly the service and use it:

constructor(private keyboard: KeyboardShortcutsService) {}
-----
this.keyboard.select('del')
omridevk commented 4 years ago

@thoussem Thank you for your suggestion, older version of the library used to work with a service, but I have decided to have more to a more declarative API and I have left the select option to keep backward compatible. I was wondering what is the use case? of using the select and not adding an action directly to the shortcut? not that I am against your suggestion, it could make sense to expose such service given that it is only exposes one method, select.

omridevk commented 4 years ago

I mean I am thinking of deprecating the select method on the component and directives, I my self couldn't find a useful case for it. as you can always make a subject and next on it with the event inside the command callback. but again, I assume your use case is valid so I might choose to expose such service, it just I want to keep the surface level of the API as thin as possible and as declarative as possible, and users not have to think about services and life cycles, destruction of events etc...