lb.core.plugins.events

Publish/Subscribe Plugin for the Sandbox API

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.plugins.eventsPublish/Subscribe Plugin for the Sandbox API
Functions
events(sandbox)Define methods in the ‘events’ property of given sandbox.
sandbox.events.subscribe(filter,callback)Create a new event subscription, triggering the callback only for events matching the provided filter.
sandbox.events.unsubscribe(filter)Remove all subscriptions for given filter.
sandbox.events.publish(event)Publish a new event for broadcasting to all interested subscribers.

Functions

events(sandbox)

Define methods in the ‘events’ property of given sandbox.

Parameters

sandboxobject, the sandbox instance to enrich with Pub/Sub methods

sandbox.events.subscribe(filter,callback)

Create a new event subscription, triggering the callback only for events matching the provided filter.

A new instance of Event Subscriber (lb.core.events.Subscriber) is created and added to the Event publisher (lb.core.events.publisher).

Parameters

filterobject, the event filter.  This object is similar to event objects.  Any included property will be used as a filter to restrict events part of the subscription.  For example:
  • {} is a subscription to all events (no filter)
  • {name: ‘foo’} is a subscription to all events named ‘foo’
  • {name: ‘foo’, id:42} filters on name===’foo’ and id===42
callbackfunction, the associated callback(event).  The event object contains at least the same properties as the filter.  In addition, custom properties may be defined by the creator of the event.

sandbox.events.unsubscribe(filter)

Remove all subscriptions for given filter.

Parameter

filterobject, an event filter.

Note

It is not necessary to provide the identical filter project provided in subscribe(); all filters with the same set of properties/values will get the corresponding subscriptions removed.

sandbox.events.publish(event)

Publish a new event for broadcasting to all interested subscribers.

Parameter

eventobject, the event to publish.  It shall be a valid JSON [1] object: no methods, no circular references.

Reference

[1] Introducing JSON (JavaScript Object Notation) http://www.json.org/

Close