I would like to use KeyboardShortcutsService by itself
nshimiye opened this issue · comments
Is your feature request related to a problem? Please describe.
I would like to use KeyboardShortcutsService
by itself
Describe the solution you'd like
import { KeyboardShortcutsService } from 'ng-keyboard-shortcuts.service';
// ...
constructor(private readonly keyboardShortcutsService: KeyboardShortcutsService) {}
ngAfterViewInit(): void {
const shortcuts = [
{
key: 'left',
label: 'Pagination',
description: 'Go to previous page',
preventDefault: true,
command: () => this.goBack()
},
{
key: 'right',
label: 'Pagination',
description: 'Go to next page',
preventDefault: true,
command: () => this.goToNext()
},
{
key: '?',
label: 'Menu',
description: 'Show keyboard shortcuts menu',
preventDefault: true,
command: () => this.openShortcutsMenu()
}
];
this.shortcutIds = this.keyboardShortcutsService.add(shortcuts);
}
ngOnDestroy(): void {
this.keyboardShortcutsService.remove(this.shortcutIds);
}
// ...
This way, my app bundle only includes the code for KeyboardShortcutsService
Describe alternatives you've considered
copy/paste the service code in my app
Additional context
I am happy to issue mr if you're ok with exposing the service
@nshimiye
Thank you for suggestion.
Since most of the written code is the KeyboardShortcutsService, not quite sure if exposing it, is worth the bundle size improvements, AFAIK the library size is 7kb gzipped minified.
https://bundlephobia.com/result?p=ng-keyboard-shortcuts@10.1.16
Version 2-4 were actually implemented only by exposing the service without the component architecture, but cleanup was tedious as the users of the library needed to unsubscribe on Destroy, while the component architecture take cares of it for the users.
Plus, exposing the service will make it a lot harder for me to change the internal API.
Have you tried forking the repository and see what the benefits of exposing the service, in the bundle size that is.
Looking forward to your answer.
And thanks again for the effort in reporting the issue/feature request.
Please reopen if still relevant