Skip to content

Manager for component-emitter to easily add or remove events from groups of objects.

Notifications You must be signed in to change notification settings

anthonyshort/emitter-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

emitter-manager

Manager for component-emitter to easily add or remove events from groups of objects. This is useful when you have groups of emitters, like models, and you want to easily remove all of the events at once.

Installation

$ component install anthonyshort/emitter-manager

API

The manager works very similar to Emitter except that on and off take an additional parameter, an emitter.

var EmitterManager = require('emitter-manager');
var manager = new EmitterManager();
var emitter = new Emitter();
var emitter2 = new Emitter();

manager.on(emitter, 'foo', function(){
  // do something
});

manager.on(emitter2, 'foo', function(){
  // do something
});

manager.off();

The advantage of managing events this way is that when you destroy an object you can just call #off and it will remove all event bindings on any objects that is is listening to. You can be specific about the events you want to remove.

manager.off();
manager.off(model);
manager.off('foo');
manager.off('foo', callback);
manager.off(model, 'foo');
manager.off(model, 'foo', callback);

Methods

EmitterManager#on(emitter, type, fn, context)
EmitterManager#off([emitter], [type], [fn])

License

MIT

About

Manager for component-emitter to easily add or remove events from groups of objects.

Resources

Stars

Watchers

Forks

Packages

No packages published