Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports only one listener per key #35

Open
plaa opened this issue Jan 27, 2019 · 0 comments
Open

Supports only one listener per key #35

plaa opened this issue Jan 27, 2019 · 0 comments

Comments

@plaa
Copy link

plaa commented Jan 27, 2019

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) });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant