Provides an interface for a publish-subscribe messaging pattern.
Objects can be decorated with an existing or new instance with the static decorate method.
Methods
(static) create() → {syngen.tool.pubsub}
Instantiates a new pubsub instance.
- Source:
Returns:
- Type
- syngen.tool.pubsub
(static) decorate(target, instanceopt) → {Object}
Decorates target with a new or existing instance and returns it.
This exposes its methods on target as if they are its own.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
target |
Object | ||
instance |
syngen.tool.pubsub |
<optional> |
- Source:
Returns:
- Type
- Object
decorate(target)
Decorates target with methods from this instance so it can be used as an event emitter.
Parameters:
| Name | Type | Description |
|---|---|---|
target |
Object |
- Source:
destroy()
Prepares the instance for garbage collection.
- Source:
emit(event)
Dispatches event to all subscribers with optional ...data.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
event |
String | ||
...data |
* |
<optional> <repeatable> |
- Source:
off(eventopt, handleropt)
Unsubscribes handler from the handlers listening for event.
If no handler is specified, then all handlers for event are removed.
If no event is specified, then all handlers for all events are removed.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
event |
String |
<optional> |
|
handler |
function |
<optional> |
- Source:
on(event, handler)
Subscribes handler to listen for event.
Parameters:
| Name | Type | Description |
|---|---|---|
event |
String | |
handler |
function |
- Source:
once(event, handler)
Subscribed handler to listen for event once.
The handler is removed after its next dispatch.
Parameters:
| Name | Type | Description |
|---|---|---|
event |
String | |
handler |
function |
- Source: