- Notifications
You must be signed in to change notification settings - Fork2
A universal, human-centric, replayable javascript event emitter.
License
lifenautjoe/noel
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A universal, human-centric, replayable event emitter.
- Motivation
- Features
- Installation
- Usage
- Creating a noel instance
- Emitting and listening to events
- Replaying events
- Disabling replay
- Enabling replay
- Removing an event listener
- Removing all event listeners
- Clearing an event replay buffer
- Clearing all events replay buffers
- Changing the events replay buffer size
- Disabling the no event listeners warning
- Enabling the no event listeners warning
- Development
The world just like software is full of events. Sometimes these events occur while we are busy doing other things. Wouldn't it be nice to have a way to replay all events? Noel is the way.
By being able to replay events we can design reactive systems without having to worry about timing.
For example, code like
// Check if there is a user in case we missed the userChanged eventconstuser=sessionService.getUser();if(user)updateAvatarPhoto(user)// Listen for further changessessionService.listenUserChanged(updateAvatarPhoto);
can become
sessionService.listenUserChanged(doSomethingWithUser).replay();
Meaning that if theuserChanged event was already fired, it will be replayed with the last arguments and if it gets fired again, we'll be listening.
- Event replaying. Never miss a beat.
- API designed for humans. No useless concepts to try to make sense of.
npm install noel
constNoel=require('Noel');constnoel=newNoel();
// Listen for an eventnoel.on('friday',partyAllNightLong);// Emit an eventnoel.emit('friday',arg1,arg2 ....);
// Replay an event oncenoel.on(eventName,eventListener).replay();// Replay an event x amount of timesnoel.on(eventName,eventListener).replay(x);
// When creating the noel instanceconstnoel=newNoel({replay:false});// At runtimenoel.disableReplay(anotherBufferSize);
Please do note thatreplay is enabled by default, so this should only be necessary if it was disabled at runtime.
// At runtimenoel.enableReplay(anotherBufferSize);
noel.removeListener(eventName,eventListener);
or if you save a reference to theeventManager
consteventManager=noel.on('myEvent',eventListener);// ...eventManager.remove();
noel.removeAllListeners(eventName,eventListener);
If you would like to clear all savedevent emissions for replay
noel.clearReplayBufferForEvent(eventName);
If you would like to clear all savedevents emissions for replay
noel.clearEventsReplayBuffers();
Or in human words, changing the amount of event emissions that are saved for replays.
Default is 1.
// When creating the noel instanceconstnoel=newNoel({replayBufferSize:aNewBufferSize});// ...// At runtimenoel.setReplayBufferSize(anotherBufferSize);
When an event is emitted, no listeners have been set AND the replay was disabled so there is no way of doing anything with the emission, a warning will be logged into the console if available. To disable this behaviour:
// When creating the noel instanceconstnoel=newNoel({noEventListenersWarning:false});// ...// At runtimenoel.disableNoEventListenersWarning();
Please do note that theno event listeners warning is enabled by default, so this should only be necessary if it was disabled at runtime.
noel.enableNoEventListenersWarning();
git clone git@github.com:lifenautjoe/noel.git
npm t: Run test suitenpm start: Runsnpm run buildin watch modenpm run test:watch: Run test suite ininteractive watch modenpm run test:prod: Run linting and generate coveragenpm run build: Generate bundles and typings, create docsnpm run lint: Lints codenpm run commit: Commit using conventional commit style (husky will tell you to use it if you haven't 😉)
AuthorJoel Hernandez
About
A universal, human-centric, replayable javascript event emitter.
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
