Installation
- Node.js, browserify
npm install multi-event --save
- Require.js
require(["multi-event"], ...
Examples
var MultiEvent = require('multi-event');
var myEvents = new MultiEvent();
var callBack = function (arg) {
console.log(arg);
};
myEvents.on('event', callBack);
myEvents.emit('event', 'this will be passed to the callback');
Multiple events Examples
var MultiEvent = require('multi-event');
var myEvents = new MultiEvent();
var myEventsSubSet = new MultiEvent();
myEvents.pipe("event2.*", myEventsSubSet);
var callBack1 = function (arg) {
console.log('callBack1 says : '+ arg);
};
var callBack2 = function (arg) {
console.log('callBack2 says : '+ arg);
};
var callBack = function (arg) {
console.log('callBack says : '+ arg);
};
var pipeCallBack = function (arg) {
console.log('pipeCallBack says : '+ arg + ' (from myEventsSubSet)');
};
myEvents.on('event.subevent1', callBack1)
.on('event.subevent2', callBack2)
.on('event.*', callBack);
myEventsSubSet.on("event2.eventViaPipe", pipeCallBack);
myEvents.emit('event.subevent1', 'this string will be logged twice');
myEvents.emit('event.subevent2', 'this string will be logged twice');
myEvents.emit('event2.eventViaPipe', 'this will be passed to the other emitter also');
EcmaScript6
This module is writen in ES6, you can find the in src/multi-event-es6.js
For building your modification run npm run build
, the files multi-event.js
and multi-event.min.js
are created in dist
folder
Build and test
- Build
npm run build
- Test
npm run test
- Watch changes and run tests and buil
npm run watch