@sz-sw/events
v2.1.4
Published
Simple event emitter module:
Downloads
6
Readme
@sz-sw/events
Simple event emitter module:
const Events = require("@sz-sw/events")
const events = Events.create(["error", "data"])
events.addEventListener("error", console.log)
events.emit("error", "Ooops!")
Events can be queued with .enqueue()
:
const Events = require("@sz-sw/events")
const events = Events.create(["error", "data"])
const flushEventQueue = events.enqueue()
events.addEventListener("error", console.log)
// Events will be queued
events.emit("error", "Ooops 1!")
events.emit("error", "Ooops 2!")
// Flush queue after 1 second
setTimeout(flushEventQueue, 1000)
Flushing the event queue will deactivate event queing.
Multiple calls to .enqueue()
are permitted.