little-emitter
A tiny event emitter for node and the browser.
Install
npm install little-emitter --save
Usage
The little-emitter can be as a CommonJS/AMD module or a method on global object, such as window
in browser.
Node:
var Emitter = ;var emitter = ; emitter;emitter; // "init"emitter;
Browser:
var emitter = ;
It can be as a mixin:
var foo = name: 'Foo' ;;// Or// new Emitter(foo);// foo = new Emitter(foo); foo;foo; // "Foo"
API
The Emitter
instance methods:
on(type, fn)
Alias: addEventListener
Attach a listener to the emitter.
once(type, fn)
Alias: one
Attach a listener which is executed at most once.
off(type, fn)
Alias: removeEventListener
/removeAllListeners
- If nothing is passed, all listeners will be removed.
- If only the
type
parameter is passed, the given type listeners will be removed. - If the
type
andfn
are specified, the earliest bound listener for the given type will be removed.
emit(type, [arg1], [arg2], ...)
Alias: trigger
Emit the specified type event and pass some arguments to the listener optionally.
getListeners(type)
Alias: listeners
Return the given type listeners or all listeners or an empty array.
License
MIT.