Event emitter with glob support on event names
Event emitter with glob support on event names, for node and the browser
- Node.js EventEmitter compatible API
- Register listeners with glob event names (
- Emit events with glob event names (
- 100% test coverage
npm install glob-events
Use Browserify to create a standalone file.
var Emitter = require'glob-events'Emitter;var emitter = ;
Emitter([opts]): Constructor function, accepting these options:
reverse: Whether to invoke listeners in reverse insertion order. Defaults to
addEvent: The event to fire when new listeners are added. Defaults to
removeEvent: The event to fire when listeners are removed. Defaults to
toScope(args): Converts the given arguments array into a scope object that can be used with
opts are passed to the glob-store constructor.
emit(event[, ...]): Invokes all listeners registered for the given event with the optional arguments. Matching rules are applied on the event name as descibed in the glob-tree match expressions.
on(event, fn): Registers a listener for an event
once(event, fn): Registers a listener for an event that is automatically removed on the first invocation
removeListener(event, fn): Unregisteres a listener for an event
removeAllListeners([event]): Unregisters all listeners, or all listeners for the given event. Matching rules are not applied.
listeners([event][, options]): Returns all listeners, or all listeners for the given event. Matching rules are applied on the event name as described in the glob-tree match expressions.
iterator([event][, options]): Exposes the iterator used to retrieve all listeners, or all listeners for a given event. Each iterator entry has these properties:
event: The event name that was used to register the function
fn: The registered function. Note: When using
once, this is not the same as the registered function.
orig: The original registered function, only available for entries that where added with
scope: The scopr to use when invoking the function.
invoke(iterator, scope): Invokes the functions returned by an iterator on the given
scopewith the arguments from
scope.args. This function is internally used by
options argument can have these properties:
matchers: Emit to matchers, defaults to
listeners: Emit to listeners, defaults to
The first argument passed to
emit can be an object with an
and any of the above options.
Listeners are invoked with a special scope object. If an object is passed to
emit as the event (see Options), that object is used as the scope object.
In addition, the arguments array is exposed via
It is also possible to bind individual listeners to specific scope objects:
emitteraddListenerevent : 'some.event'scope : this;
newListener: Emitted by
oncewith the event name and the new listener function. Matchers will not receive this event.
removeListener: Emitted by
removeAllListenerswith the event name and the removed listener function. Matchers will not receive this event.
error: Emitted by
emitif a listener throws an exception. The only argument is the caught exception. The original event's scope is exposed on
this.causewith these properties:
event: The event that caused the exception
fn: The function that threw the exception
scope: The scope the function was executed with
args: The arguments that where passed to the function