Skip to content

Missing EventSubscribeHandler and EventUnsubscribeHandler implementation #200

Closed
@erkann-sen

Description

@erkann-sen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreIssues with the core library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions