Simple and fast event emitter library. Subscription is based on a unique Token, which can be used to unsubscribe from the topic.
The Eventer is used in LightningChart® JS charting library. https://www.arction.com/
npm install --save @arction/eventer
Online documentation is available at arction.github.io/eventer
// new topic is created, handler is added as the first subscriber to the topic// 'topic1' already exists, so new listener is simply added to existing collection of handlers// new collection of handlers is created for the second topic// the function is added to iteventer.on'topic2',console.log'I am called from topic2'eventer.emit'topic1'// calls two functions which listen to the event//// outputs:// I am called from topic1// I am also called from topic1eventer.emit'topic2'// calls single functions which listen to the event//// outputs:// I am called from topic2// remove the second listener from the first topic by tokeneventer.offtoken2eventer.emit'topic1'// calls single functions which listen to the event//// outputs:// I am called from topic1// remove all listeners from all topicseventer.allOffeventer.emit'topic2'// nothing happened, since all subscriptions were terminated
Subscribe to topic
Subscribing to a topic is easy.
Multiple subscriptions to a single topic can exist.
Unsubscribe from topic
You can unsubscribe from a single topic by using the Token returned by eventer when you subscribed to the topic.
You can also unsubscibe all listeners from a topic.
It is also possible to unsubscribe all topics and all listeners.
Events can be emitted for a topic. The emit can contain 0 or more arguments that will be provided to the topic listeners.
eventer.emit'topic'eventer.on'topic2',console.log arg1, arg2eventer.emit'topic2', 'Hello ', 'World'
The project is developed using TypeScript. Build system of the project heavily relies on Node.js. Dependencies are managed with npm, therefore, remember to run npm install before starting of anything else.
There are several npm scripts, which are used for development process:
|build||npm run build||run build system|
|test||npm test||run tests and watch|
|lint||npm run lint||run static analyzer and watch|
|docs||npm run docs||generate typedoc documentation|
|ci:test||npm run ci:test||run tests once|
|ci:lint||npm run ci:lint||run static analyzer once|
|ci:watch||npm run ci:watch||run CI circle and watch|