lb.core.events.Subscriber

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.

Authors

Copyright

Eric Bréchemier © 2011, Some Rights Reserved Legal-Box SAS © 2010-2011, All Rights Reserved

License

BSD License http://creativecommons.org/licenses/BSD/

Version

2011-08-14

Summary
lb.core.events.SubscriberSubscriber to Core Events
Functions
new Subscriber(filter,callback): SubscriberConstructor of a new Core Events Subscriber.
getFilter(): objectGet the associated filter object.
includes(event, filter): booleanCheck 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.

Functions

new Subscriber(filter,callback): Subscriber

Constructor of a new Core Events Subscriber.

Parameters

filterobject, the set of properties/values expected in events
callbackfunction, 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.

Returns

object, the new instance of Subscriber

getFilter(): object

Get the associated filter object.

Returns

object, the filter provided in constructor

includes(event, filter): boolean

Check whether event object includes filter object.

Parameters

eventobject, first filter object
filterobject, second filter object

Returns

true when every property in filter has the same value in event, false otherwise

Note

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.

notify(event)

Apply the filter to incoming event and trigger the callback if the event matches the expected filter.

Parameters

eventobject, the incoming event object

The filtering principle is

  • a filter without any property accepts all incoming events
  • any property set on the filter must be found with the same value on the incoming event.  If the property is not present, or present with a different value, the incoming event is rejected.

Note

The input event is cloned recursively before being provided to the target callback, which can then keep it and update it freely.

Close