atomic-emitter
Similar to Raynos' geval, with the following changes:
- will proxy the whole arguments to listeners
Example
atomic-emitter
has an interface similar to geval's SingleEvent. You can pass it around, add listeners and emit events.
var Emitter = var clicksEmitter = var removeListener = document // ... // and you will stop listening to events
You can also restrict write access to the creator of the emitter, if you want:
var Emitter = var clicksEmitter = var removeListener = clicksEmitter // Will throw an exception // ... // and you will stop listening to events
The purpose of this is that you no longer have an EventEmitter-inherited object with obscure events, but a normal everyday-object with some of its properties populated with atomic emitters as values -- events are real values now. For example:
var stream = ondata: onclose:
API
Emitter(fn:Function(emit:Function)): Emitter
Create an atomic emitter with an emit function passed to the creating code.
Emitter(): Emitter
Create an atomic emitter with a public emit function.
emitter(listener:Function)
Add an event listener.
emitter.emit(args...)
Emit the event.
Legal
(c) 2015 by Marcel Klehr
MIT License