A very simple event emitter with a better API than all the others.
It's better because:
onandoncereturn an unsubscribe function- It doesn't use
this, which means you can pass around theonoremitfunctions - It can take in any existing object and turn it into an emitter
Also, it's pretty simple. Check out the source code.
npm i better-emitterconst createEmitter = require('better-emitter')
API
const emitter = createEmitter()
const unsubscribe = emitter.on('thing happened', (really, why) => {
really // => true
why // => 'I dunno'
})
emitter.emit('thing happened', true, 'I dunno')
unsubscribe()emitter = createEmitter([emitter])
This is the function exported by the module. It creates a new event emitter object. You can also pass in any object you want, and event emitter functions will be added to it.
unsubscribe = emitter.on(eventString, listenerFunction)
Adds an event listener function. Returns an unsubscribe function that, when called, prevents the listener from firing any more.
unsubscribe = emitter.once(eventString, listenerFunction)
Just like the on function, except the listener is automatically unsubscribed after the first time the event is emitted.
emitter.emit(eventString, [...args])
Calls all listeners of the given event string, with any arguments.
emitter.removeAllListeners()
Unsubscribes all current event listeners.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
