Supports only one listener per key
plaa opened this issue · 0 comments
plaa commented
The tutorial telemetry provider implementation supports only one subscriber per key. Later subscriptions overwrite the listener. Each key should have an array of listeners instead.
While the implementation works for the exact tutorial use case, it breaks if you add additional graphs. The tutorial may also used as a basis for further development, so it can be a source of much confusion.
A proper implementation would be for example:
subscribe: function (domainObject, callback) {
var key = domainObject.identifier.key
listener[key] = listener[key] || []
listener[key].push(callback);
return function unsubscribe() {
var index = listener[key].indexOf(callback);
if (index > -1) {
listener[key].splice(index, 1);
}
};
}
Correspondingly calling the listeners:
listener[key].forEach(function(l) { l(point) });