Socket
Socket
Sign inDemoInstall

multi-event

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    multi-event

Simple event emitter that supports triggering listener to multiple events


Version published
Weekly downloads
9
decreased by-10%
Maintainers
1
Install size
26.7 kB
Created
Weekly downloads
 

Readme

Source

Build Status

Installation

  • Node.js, browserify npm install multi-event --save
  • Require.js require(["multi-event"], ...

Examples

var MultiEvent = require('multi-event'); // require it
var myEvents = new MultiEvent();

// Implement listener
var callBack = function (arg) {
    console.log(arg);
};

// Register callBack event listener
myEvents.on('event', callBack);

myEvents.emit('event', 'this will be passed to the callback');
// shows 'this will be passed to the callback' in console

Multiple events Examples

var MultiEvent = require('multi-event'); // require it
var myEvents = new MultiEvent();
var myEventsSubSet = new MultiEvent();

myEvents.pipe("event2.*", myEventsSubSet);

// Implement listener
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)');
};


// Register callBack event listener
myEvents.on('event.subevent1', callBack1)
        .on('event.subevent2', callBack2)
        .on('event.*', callBack); // this callBack is trigged to all 'event' sub-events
        
myEventsSubSet.on("event2.eventViaPipe", pipeCallBack);

myEvents.emit('event.subevent1', 'this string will be logged twice');
// the following will be displayed on the console
//  callBack1 says : this string will be logged twice
//  callBack says : this string will be logged twice
myEvents.emit('event.subevent2', 'this string will be logged twice');
// the following will be displayed on the console
//  callBack2 says : this string will be logged twice
//  callBack says : this string will be logged twice

myEvents.emit('event2.eventViaPipe', 'this will be passed to the other emitter also');
// the following will be displayed on the console
//  pipeCallBack says : this will be passed to the other emitter also (from myEventsSubSet)

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

Keywords

FAQs

Last updated on 24 Nov 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc