Notificar - A Cooler Event Library
Features include:
- Unlike
on
,off
,addListener
,removeListener
etc.Notificar
event subscriptions return aDisposable
object withdispose()
method to unsubscribe from event. - Above feature allows you to group event subscriptions using
DisposablesComposite
and dispose them all with one call, i.eDisposableComposite#dispose()
- Listeners voice matters!! You can now dispatch an event using
Notificar#dispatchWithReturn
where each listener's return value can be accessed from returned array.
The Last feature can come in handy like in example below:
// Here some listeners are subscribed to `onWillCommit` event, but we can allow listeners to disagree if they deem so { // ... // here we'll notify all `will-commit` listeners, but if one of them returns false, we'll abort the `commit` operation if thisnotificar return // Proceed with commit opertaion // ...}
Usage
npm i notificar
// Textbuffer.ts (I highly recommend TypeScript as you can get a huge performance boost by using `enum`s instead of strings as event identifiers) // ...
Full API can be found in index.d.ts
License
MIT © 2018 Neek Sandhu