podium

Node compatible event emitter with extra features

This module has moved and is now available at @hapi/podium. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
Last updated 2 years ago by hueniverse .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install podium 
SYNC missed versions from official npm registry.

podium

Node (semi) compatible event emitter with extra features.

Build Status

License

This version of the package requires a commercial license. You may not use, copy, or distribute it without first acquiring a commercial license from Sideway Inc. Using this software without a license is a violation of US and international law. To obtain a license, please contact sales@sideway.com. The open source version of this package can be found here.

About

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 it's overhead is largely insignificant as implementing these features will have similar cost on top of the native emitter.

new Podium(events)

This creates a new event emitter.

const Podium = require('podium');
const podiumObject = new Podium(); // new emitter

const podiumObject2 = new Podium('event1');// creates new event and calls registerEvent()

podium.registerEvent(events)

Registers an event event1 to emitter.

podiumObject.registerEvent('event1');

//with optional parameters
podiumObject.registerEvent({
        name: 'event1',
        shared: true
 });

podium.on(criteria, listener)

Subscribe a handler to an event. Handler can be seen a function which will be called when the event occurs.

podiumObject.registerEvent('event1');

podiumObject.on('event1',function(update){ // Way 1
    console.log('inside autonomous listener without name! data:', update);
});

const listener1 = function() { // normal function object
    console.log('listener1 called');
}
podiumObject.on('event1',listener1); // Way 2

podium.addListener(criteria, listener)

Same as podium.on().

podiumObject.addListener('event1',listener1);

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.once('event1',listener1);

podium.emit(criteria, data, [callback])

Emits an event update to all the subscribed listeners.

podiumObject.emit('event1','here we can send any data to listeners.');

podium.removeListener(name, listener)

Removes all listeners subscribed to a given event name matching the provided listener method.

podiumObject.removeListener('event1',listener1);

podium.removeAllListeners(name)

Removes all listeners subscribed to a given event name.

podiumObject.removeAllListeners('event1');

podium.hasListeners(name)

Returns whether an event has any listeners subscribed.

if(podiumObject.hasListeners('event1')){
    console.log('this event has some listeners left');
}
else{
    console.log('this event has no listeners');
}

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 reverse is not true.

const source1Object = new Podium('test');
const source2Object = new Podium('test');

const emitterObject = new Podium(source1Object);
emitterObject.registerPodium(source2Object);

const listener1 = function() { // normal function
    console.log('listener1 called');
}
const listener2 = function() { // another normal function
    console.log('listener1 called');
}
emitterObject.on('test',listener1); // listener1 gets registered on emitterObject, source1Object,source2Object events
source1Object.on('test',listener2); // listener2 gets registered on source1Object events only

source1Object.emit('test', 1); // runs all registered events
emitterObject.emit('test', 2);

API

The full API is available in the API documentation.

Current Tags

  • 3.2.0                                ...           latest (2 years ago)

22 Versions

  • 3.2.0 [deprecated]           ...           2 years ago
  • 3.1.5 [deprecated]           ...           2 years ago
  • 3.1.4 [deprecated]           ...           2 years ago
  • 3.1.3 [deprecated]           ...           2 years ago
  • 3.1.2 [deprecated]           ...           3 years ago
  • 3.1.1 [deprecated]           ...           3 years ago
  • 3.0.0 [deprecated]           ...           3 years ago
  • 2.1.0 [deprecated]           ...           3 years ago
  • 2.0.3 [deprecated]           ...           3 years ago
  • 2.0.2 [deprecated]           ...           3 years ago
  • 2.0.1 [deprecated]           ...           3 years ago
  • 2.0.0 [deprecated]           ...           3 years ago
  • 1.3.0 [deprecated]           ...           3 years ago
  • 1.2.5 [deprecated]           ...           4 years ago
  • 1.2.4 [deprecated]           ...           4 years ago
  • 1.2.3 [deprecated]           ...           4 years ago
  • 1.2.2 [deprecated]           ...           4 years ago
  • 1.2.1 [deprecated]           ...           4 years ago
  • 1.2.0 [deprecated]           ...           4 years ago
  • 1.1.0 [deprecated]           ...           4 years ago
  • 1.0.0 [deprecated]           ...           4 years ago
  • 0.0.0 [deprecated]           ...           4 years ago
Maintainers (1)
Downloads
Today 73
This Week 109
This Month 442
Last Day 36
Last Week 206
Last Month 1,310
Dependencies (2)
Dev Dependencies (3)
Dependents (3)

Copyright 2014 - 2016 © taobao.org |