zemitter

0.2.5 • Public • Published

zemitter

Flexible Event Emitter for Node and the Browser

Install

$ npm install zemitter

Usage

var Emitter = require('zemitter')
var obj = {}
 
//either make an object become an event emitter
Emitter(obj) // returns obj
 
//or create a brand new emitter
var emitter = Emitter()

Example

emitter.on({
    start: function(greeting, name){
        console.log(greeting, name)
    },
    stop: function(){
 
    },
    scope: {}
})
emitter.on('start', function(){
 
})
emitter.on({
    start: {
        fn: function(){
 
        },
        scope: ''
    },
    stop: function(){}
})
 
emitter.emit('start', 'hello', 'world')

API

on

emitter.on({
    'event_name': fn
})
emitter.on(['start','stop','exit'], fn)
emitter.on(['start','stop','exit'], [fn1, fn2])

off

emitter.off('start', fn)// remove fn as a listener to the 'start' event emitter.off('start') // remove all listeners to the start event emitter.off() // remove all listeners attached to this emitter

once

Attach a function that will only be called once, and then will be removed from the emitter

Tests

$ make

License

MIT

Package Sidebar

Install

npm i zemitter

Weekly Downloads

10

Version

0.2.5

License

MIT

Last publish

Collaborators

  • radubrehar