microevent2.js
microevent2.js is a event emitter library which provides the observer pattern to javascript objects.
It works on ES6, node.js and browser. It is a single.js file containing
< a href = "https://raw.githubusercontent.com/sun2rise/microevent2/master/dist/microevent2.js" >
Usage
You need a single file microevent2.js. Include it in a webpage via the usual script tag.
var microevent2 = ; microevent2;microevent2;
or
;let { MicroEvent2; this;}
or
var Microevent2 =
Instance Methods
on(event, callback)
Subscribe to an event
event
- the name of the event to subscribe tocallback
- the function to call when event is emitted
once(event, callback[, context])
Subscribe to an event only once
event
- the name of the event to subscribe tocallback
- the function to call when event is emitted
off(event[, callback])
Unsubscribe from an event or all events.
event
- the name of the event to unsubscribe fromcallback
- the function used when binding to the event
emit(event[, arguments...])
Trigger a named event
event
- the event name to emitarguments...
- any number of arguments to pass to the event subscribers
pipe(eventEmitter)
Push events downstream from the handler to another
eventEmitter
- the event emitter to pipe (to emit to)
unpipe(eventEmitter)
Unpipe events to the previously piped event emitter
eventEmitter
- the event emitter to unpipe
mixin(destObject)
Mixin will delegate all microevent2 function in the destination object
destObject
- the object which will support microevent2
bind
For compatibility, see on
unbind
For compatibility, see off
trigger
For compatibility, see emit
Example
see inside test
folder