podium
Node (semi) compatible event emitter with extra features.
podium is an event emitter with support for tags, filters, channels, event update cloning,
arguments spreading, and other features useful when building large scale applications.
While node's native EventEmitter
is strictly focused on maximum performance,
it lacks many features that do not belong in the core implementation. podium is not restricted by
node's performance requirement as it is designed for application layer needs where its overhead
is largely insignificant as implementing these features will have similar cost on top of the native emitter.
Lead Maintainer - Eran Hammer
new Podium(events)
This creates a new event emitter.
const Podium = ;const podiumObject = ; // new emitterconst podiumObject2 = 'event1';// creates new event and calls registerEvent()
podium.registerEvent(events)
Registers an event event1
to emitter.
podiumObject; //with optional parameterspodiumObject;
Using different parameters
podium.on(criteria, listener)
Subscribe a handler to an event. Handler can be seen as a function which will be called when the event occurs.
podiumObject;podiumObject; const listener1 = { // normal function object console;}podiumObject; // Way 2
podium.addListener(criteria, listener)
Same as podium.on()
.
podiumObject;
podium.once(criteria, listener)
Same as calling podium.on()
with the count option set to 1. Whenever we call emit()
, listener1
will get fired
but also get removed, so that it won't get fired on call to emit()
.
podiumObject;
podium.emit(criteria, data, [callback])
Emits an event update to all the subscribed listeners.
podiumObject;
podium.removeListener(name, listener)
Removes all listeners subscribed to a given event name matching the provided listener method.
podiumObject;
podium.removeAllListeners(name)
Removes all listeners subscribed to a given event name.
podiumObject;
podium.hasListeners(name)
Returns whether an event has any listeners subscribed.
if podiumObject console;else console;
podium.registerPodium(podiums)
Registers a podium object(emitter) to another podium object(source). Whenever any event gets registered on emitterObject
it gets registered on sourceObject
as well. But the reverse is not true.
const source1Object = 'test';const source2Object = 'test'; const emitterObject = source1Object;emitterObject; const listener1 = { // normal function console;}const listener2 = { // another normal function console;}emitterObject; // listener1 gets registered on emitterObject, source1Object,source2Object eventssource1Object; // listener2 gets registered on source1Object events only source1Object; // runs all registered eventsemitterObject;
Cookbook
channels
const Podium = ;const podiumObject = ; podiumObject;const listener1 = { console;};const listener2 = { console;}; podiumObject; podiumObject; podiumObject; var arr = 0 1 2 3 4 4 5; podiumObject;
clone
const Podium = ;const podiumObject = ; podiumObject; const listener1 = { data0 = 55; console;};const listener2 = { data0 = 100; console;}; podiumObject; podiumObject; var arr = 0 1 2 3 4 4 5; console; podiumObject; console; podiumObject; console;
spread
const Podium = ;const podiumObject = ; podiumObject; const listener1 = { console;}; const listener2 = { data0 = 100; console;}; podiumObject; podiumObject; var arr = 0 1 2 3 4 4 5; console; podiumObject; console; podiumObject;console;
shared
const Podium = ;const podiumObject = ; podiumObject;podiumObject;const listener2 = { console;}; podiumObject; var arr = 0 1 2 3 4 4 5; podiumObject;
tag-filter
const Podium = ;const emitter = 'test'; const updates = ;emitter;emitter;emitter;emitter;emitter; emitter;emitter;emitter;emitter;emitter; emitter;
count
const Podium = ;const podiumObject = ; podiumObject; const listener1 = { console;}; podiumObject; podiumObject;podiumObject;podiumObject; // this wont call listener1
API
The full API is available in the API documentation.