0.1.1 • Published 7 years ago
yaemit-extras v0.1.1
yaemit-extras
Extras for a microscopic and speedy event emitter.
npm --save install yaemit yaemit-extras
Usage
Run an event handler once:
import Emitter from 'yaemit'
import { once } from 'yaemit-extras'
const OEmitter = once(Emitter)
const o = new OEmitter()
o.once('event', handler)
o.emit('event') // Ran event handler
o.emit('event') // Didn't run anything
Enable chaining:
import { chain } from 'yaemit-extras'
const CEmitter = chain(Emitter)
const c = new CEmitter()
c.emit('one').emit('two').emit('three')
Emit events when .on and .off are used:
import { notify } from 'yaemit-extras'
const NEmitter = notify(Emitter)
const n = new NEmitter()
n.on('off', () => console.log('off'))
n.off('off') // Runs console.log('off')
Combine mixins:
const SEmitter = once(chain(Emitter))
const spiffy = new SEmitter()
spiffy
.emit('spaghetti') // Didn't run anything
.once('spaghetti', handler)
.emit('spaghetti') // Ran event handler
.emit('spaghetti') // Didn't run anything