misoproject/events

Name: events

Owner: The Miso Project

Description: Basic event subscription & binding that can be easily attached to any object. Currently used in most of our libraries.

Created: 2012-11-14 19:13:23.0

Updated: 2017-10-19 07:56:44.0

Pushed: 2012-11-16 18:30:27.0

Homepage: null

Size: 231

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Miso.Events

Miso.Events is a small collection of methods that enables an object to publish events and allows others to subscribe to it.

To add it to your code, mix it in like so:

yourObject = {};
tend(yourObject, Miso.Events);

If you have a constructor, make sure to extend the prototype:

YourObject = function() {};
tend(YourObject.prototype, Miso.Events);
API
Publishing

this.publish(name, *...)

Allows an evented object to publish/broadcast an event to its subscribers.

Example
myObject = function(){
is.publish('initialized', 1, 2, 3);

Subscribing

anObject.subscribe(name, callback, options)

Allows one to subscribe to events events.

Options can include:

Example
myObject = {};
tend(myObject, Miso.Events);

ject.subscribe('greet', function() {
nsole.log("say hi");

Subscribing Once

`anObject.subscribeOnce(name, callback, options);

When wanting to react to an event only the first time it triggers, use the subscribeOnce method. The rest of the parameters are identical to the subscribe ones.

Unsubscribe

Allows unsubscringing from a specific event.

myObject.unsubscribe(name, identifier)

The identifeir can be:

You can omit the identifier to unsubscribe all events for a particular name.

Contributing

To build Miso.Events you'll need npm, node.js's package management system and grunt

npm install

To build Miso.Events, call

grunt

from the project root.

Questions?

Please submit an issue or find @iros (@ireneros on twitter) or @alexgraul.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.