-
Notifications
You must be signed in to change notification settings - Fork 0
EventEmitter.once
Dragiyski edited this page Mar 28, 2015
·
2 revisions
This method adds a listener that is removed automatically after it has been called.
emitter.once(event, listener, dependencies)| Argument | Type | Required | Description |
|---|---|---|---|
| event | string | ✓ | The name of the event. |
| listener | function | ✓ | The listener function added for that event. |
| dependencies | array or array-like object of functions | List of dependencies for that listener. |
The this EventEmitter instance.
- Throws a
TypeErrorwhen listener is not a function. - Throws a
TypeErrorwhen dependencies is array or array-like objects, but contain other than function. - Throws a
ReferenceErrorwhen dependencies contain the listener (e.g. attempt to make listener dependency of itself).
If a dependency is not added for as a listener for the given event, it'll be added as long as there are dependent listeners for it.
If listener already added for the specified event, following operation might happen:
- If a listener is added as dependency by some early call, it'll be promoted to
oncelistener. If listener is normal listener, it'll remain a normal listener. - If a list of dependencies is specified, it'll merged with current dependencies.
In case once called with listener that is already added as a normal listener, dependencies specified by once should be removed after the first call.