Subscriber to Core Events
A Subscriber acts as a filter between the Publisher of Core Events and callbacks registered by Modules.
All subscribers get notified of all events. Each subscriber will apply the filter configured during its creation to decide whether the associated callback shall be triggered or not.
In this module, a filter consists of a set of properties with values. The same property must be present with the same value for the callback to get triggered.
Eric Bréchemier © 2011, Some Rights Reserved Legal-Box SAS © 2010-2011, All Rights Reserved
BSD License http://creativecommons.org/licenses/BSD/
2011-08-14
lb. | Subscriber to Core Events |
Functions | |
new Subscriber(filter,callback): Subscriber | Constructor of a new Core Events Subscriber. |
getFilter(): object | Get the associated filter object. |
includes(event, filter): boolean | Check whether event object includes filter object. |
notify(event) | Apply the filter to incoming event and trigger the callback if the event matches the expected filter. |
Constructor of a new Core Events Subscriber.
filter | object, the set of properties/values expected in events |
callback | function, the associated callback function to trigger. A matching event will trigger the callback, and be provided as parameter: callback(event). The provided parameter is a deep clone of the input event, and can thus be kept at hand and updated freely by the target module. |
object, the new instance of Subscriber
Check whether event object includes filter object.
event | object, first filter object |
filter | object, second filter object |
true when every property in filter has the same value in event, false otherwise
This method is intended for internal use in this module to check whether an event includes a filter; it is also used in the Sandbox, to compare the mutual inclusion of two filters and check equality.
Apply the filter to incoming event and trigger the callback if the event matches the expected filter.
event | object, the incoming event object |
The input event is cloned recursively before being provided to the target callback, which can then keep it and update it freely.