new observers.Subject()
The Subject type.
The observer pattern is a software design pattern in which an object, named the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.
- Source:
Methods
notify(message, …args)
Notify all observers listening to a given message type.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
message |
string | the message type. |
|
args |
* |
<repeatable> |
a list of arguments to pass to each callback. |
- Source:
numberOfObservers(message) → {number}
Returns the number of observers for a given message type.
Parameters:
Name | Type | Description |
---|---|---|
message |
string | the observed message. |
- Source:
Returns:
the number of observers.
- Type
- number
register(message, observer)
Register a callback for a given message type.
Parameters:
Name | Type | Description |
---|---|---|
message |
string | the message to observe. |
observer |
function | the callback to notify. |
- Source:
unregister(message, observer)
Unregister a callback for a given message type.
Parameters:
Name | Type | Description |
---|---|---|
message |
string | the observed message. |
observer |
function | the notified callback. |
- Source: