gritzko/swarm

Proper object unregistering from host

nvartolomei opened this issue · 4 comments

Hello,

As far as I can see a specific swarm host (client) will receive events only for objects in use, currently I'm building an app prototype using React, I have multiple documents, when I open first document host.get('/Text#1) client's swarm host will receive events only for this specific object, now I want to close this document and open a new one (without refreshing), host.get('/Text#2), now my swarm host will receive and will handle events for both objects (I can see this in browser's console). How can I make swarm host to not handle events for first object anymore?

host.unregister does not solve this.

Thanks

Calling .close() on object gives this error Uncaught TypeError: undefined is not a function on this line uplink.off(s, null, this);

ps. swarm 0.3.25

Hello, from the last comment I understand you closed the host .close() ? Also when you are using the host.get("/SomeObject") - this will return the syncable object on which you can add event listeners, seems like you want remove the event listeners from the object ? Comments from @gritzko, @abalandin ?

Syncable has close() too.
Ideally, that close() call must unsubscribe it from any uplink sources.
That is exactly what @nvartolomei wants.
Practically, uplinks are Pipes, so an .off op must be transmitted by the pipe (like /MyType#myid!time.off) to prevent any further events from coming.
pipe.off is syntactic sugar that was removed at some point, because who needs sugar in internal interfaces?
The actual issue here is the lack of test case for unsubscription.

@gritzko you understand me right, I want to unsubscribe from uplinks, because at some point I'm not interested anymore in some object, but I keep receiving updates.

Any way to do it?