-
Notifications
You must be signed in to change notification settings - Fork 0
Events
Ionut Moraru edited this page Mar 14, 2015
·
3 revisions
The library implements a pub/sub arhitecture and uses channels to send/receive data between the modules, framework, and the application.
The library can be access globally via the window
object (window.events
) or just by the name events
. It also implements caching as the the calls are routed through the DataStore service.
Example (get the outputs for all buildings in a facility):
var facility_id = 1;
events.publish('get', {
topic: 'service:facilities/id:' + facility_id + '/controller:buildings',
caller: id + ':buildings'
});
events.subscribe(id + ':buildings', function(data) {
var buildings = data.data;
_.each(buildings, function(building) {
events.publish('get', {
topic: 'service:buildings/id:' + building.id + '/controller:outputs',
caller: building.id + ':outputs'
});
});
events.subscribe(building.id + ':outputs', function(data) {
var outputs = data.data;
// use outputs
});
});
More documentation can be found in the source code.