arbitrary-emitter
Event emitter with Map/Set sugar for browser and node.js apps
arbitrary-emitter allows to use arbitrary values as keys for your events
arbitrary-emitter is written in vanilla ES6, so maybe you want to transpile it before using it.
Project in active development, API may change
Create a new emitter
const emitter = arbitraryEmitter()
Emitter API
add(key, method)
Add a listener for key
which will trigger method
function.
key
can be any type of value.
add
returns unsubscribe method
const obj = {}
let unsubscribe = emitter.add(obj, () => doSomething())
emitter.trigger(obj)
unsubscribe()
emitter.trigger(obj)
addOnce(key, method)
Add a listener for key
which will trigger method
function just one time, then listener will be removed.
key
can be any type of value
const obj = {}
emitter.addOnce(obj, () => doSomethingOnce())
emitter.trigger(obj)
emitter.trigger(obj)
emitter.trigger(key)
Trigger methods binded to key
emitter.trigger(obj)
Testing
Node
npm test
© 2016 Jacobo Tabernero - Released under MIT License