Description
I have needed to make an action when an event in exposed thing is subscribed. But normal api only allows me to subscribe to an event unsubscribe or emit an event. To make it happen I dive deep in exposed_thing.js and it triggers an action when somebody is subscribed an event.
So my proposal is to have a callback for any developer to have knowledge if somebody subscribed to event. Something like thing.on_subscribed_to_event(eventName, subscribedCount)
I made this functionality by overriding push function of thing.events[eventName].getState().subject.observers array as a hacky way (code below).
But it also showed me another problem unsubscription does not make any change in subjects observers it does not remove the observers, they stay forever in this array so overriding pop function or relying on sub.observers.length
let sub = this.thing.events[eventName].getState().subject; sub.observers.push = function () { Array.prototype.push.apply(this, arguments); if (sub.observers.length == 1) { /*sth subscribed for the first time*/ this.handleFirstTimeSubscriptionForEvent(eventName); } };