class Observable
The Observable class is a simple implementation of the Observable pattern.
There's one slight particularity though: a given Observable can notify its observer using a particular mask value, only the Observers registered with this mask value will be notified.
This enable a more fine grained execution without having to rely on multiple different Observable objects.
For instance you may have a given Observable that have four different types of notifications: Move (mask = 0x01), Stop (mask = 0x02), Turn Right (mask = 0X04), Turn Left (mask = 0X08).
A given observer can register itself with only Move and Stop (mask = 0x03), then it will only be notified when one of these two occurs and will never be for Turn Left/Right.
Name | Type | Description | |||
---|---|---|---|---|---|
optional | onObserverAdded | observer | Observer<T> |
|
Create a new Observer with the specified callback
Name | Type | Description | |||
---|---|---|---|---|---|
callback | eventData | T | |||
eventState | EventState |
| the callback that will be executed for that Observer optional | mask | number | the mask used to filter observers optional | insertFirst | boolean | if true the callback will be inserted at the first position, hence executed before the others ones. If false (default behavior) the callback will be inserted at the last position, executed after all the others already present.
Remove an Observer from the Observable object
Name | Type | Description | |
---|---|---|---|
observer | Nullable<Observer<T>> | the instance of the Observer to remove. If it doesn't belong to this Observable, false will be returned. |
Remove a callback from the Observable object
Name | Type | Description | |||
---|---|---|---|---|---|
callback | eventData | T | |||
eventState | EventState |
Notify all Observers by calling their respective callback with the given data
Will return true if all observers were executed, false if an observer set skipNextObservers to true, then prevent the subsequent ones to execute
Name | Type | Description | |
---|---|---|---|
eventData | T | ||
optional | mask | number | |
optional | target | any |
Notify a specific observer
Name | Type | Description | |
---|---|---|---|
observer | Observer<T> | ||
eventData | T | ||
optional | mask | number |
return true is the Observable has at least one Observer registered
Clear the list of observers
Clone the current observable
Does this observable handles observer registered with a given mask
@return {boolean} whether or not one observer registered with the given mask is handeled
Name | Type | Description | |
---|---|---|---|
optional | mask | number |