Event emitter, but for hooks
Often event emitters are used not for sending signals to the outside world but as a general purpose hooking API. The difference is that hooks are known in advance, they are not specific to concrete instance. The natural thing to do for such cases is:
Obviously traditional event emitters do not allow that. They force you to do all subscriptions in constructor. That is
Super.call(this)is a smell)
This project implements emitter in a different way. It allows you to add
subscriptions on prototype and generally you should not think about clobbering
Emitter.call(this) calls. At the moment of writing it can be used as a
drop in replacement for component/emitter.
var Emitter =var calls =var proto =protovar instance = Objectinstanceinstancecallsshouldprotocallsshould
Addition of handlers to prototype when child instance was already created is not supported. For such case behaviour is undefined.
var proto =var instance = Objectproto // that's a bit funkyinstance
npm install hooks-emitter
component install eldargab/hooks-emitter
var Emitter = ;var emitter = ;emitter;
As a mixin:
var Emitter = ;var user = name: 'tobi' ;;user;
Register a single-shot
removed immediately after it is invoked the
fn, or pass only the
name to remove all handlers for
event with variable option args.
Return an array of callbacks, or an empty array.
Check if this emitter has