nasa / openmct-tutorial

A tutorial for OpenMCT that guides you through integrating historical and realtime telemetry.
Other
244 stars 106 forks source link

Supports only one listener per key #35

Open plaa opened 5 years ago

plaa commented 5 years ago

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) });