A central object for event listening and emitting with advanced execution controls.
See chain-builder for how event listeners are executed.
See ordering for how event listeners are ordered within an event chain.
See needier for
ordering sorts based on dependencies.
See eventa for another event system.
npm install event-nexus --save
// get the module's builder functionvar buildNexus =// the only build option is `contextBase`.// it can have constants as well as functions// anything in it will be available in the execution context// given to each event listener functionvar buildOptions = contextBase: some: 'stuff'// build the nexus with the optionsvar nexus = ;// add an event listenernexus;// to use a custom context base for an individual event chain,// instead of all event chains, create the event chain manually// and specify the options:// (true means create if it isn't created)nexus;// you can do a `once` listener as well.// or, if you want it to execute 2 or more times depending on something:nexus;// both `on` and `once` allow specifying multiple listeners at once.// they accept them as a list of params, or, as a single param arraynexus;nexus;// remove a listener:nexus// remove all event listeners for a specific event:nexusclear'event name';// OR: remove all event listeners for *all* events:nexusclear;// finally, emit event with a name and, optionally, an event objectvar eventObject = some: 'thing' ;nexus;// a listener for the above example:nexus;
- on - add listener(s)
- once - same as
on()except they run only once
- off - remove a listener
- clear - remove all listeners for all events, or, for a specific event
- emit - usual emitter accepts event name and an event object
- accept a callback in
emit()which is added as a one-time 'done' event listener on the chain.