Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

a stupidly tiny event emitter

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 .npmignore
Octocat-spinner-32 README.md
Octocat-spinner-32 package.json
README.md

emi

install

npm install emi

use

inherit from emi

var emitter = require("emi")

var X = function(){...}

X.prototype = new emitter

copy emi properties to object

var emitter = require("emi")

var X = function(){...}

emitter(X)

then

X.prototype.doSomething = function(isBad){
    if (isBad) this.emit("bad", "very bad stuff happening", "today")
    else this.emit("good", "very good stuff happening", "today")
}

var x = new X

var badLog = function(message, day){
    console.error(message)
}

x.on("bad", badLog)

var goodLog = function(message, day){
    console.log(message)
};

x.on("good", goodLog)

x.doSomething(true) //emits bad
x.doSomething(false) //emits good

x.off("good", goodLog)
x.off("bad", badLog)

x.doSomething(true) //emits nothing
x.doSomething(false) //emits nothing

license

MIT@me

Something went wrong with that request. Please try again.