Hello,
On the Phoenix Channels JavaScript client side, is there a way to remove an event listener aka channel.on("new_message", msg => do_something)
? Something like channel.unsubscribe("new_message")
.
Thanks
Hello,
On the Phoenix Channels JavaScript client side, is there a way to remove an event listener aka channel.on("new_message", msg => do_something)
? Something like channel.unsubscribe("new_message")
.
Thanks
I believe it’s channel.off("new_message")
Indeed I found this in the source code:
on(event, callback){ this.bindings.push({event, callback}) }
off(event){ this.bindings = this.bindings.filter( bind => bind.event !== event ) }
which looks good.
------------ EDIT -------------------
and that in the official js client source code
key: "on",
value: function on(event, callback) {
this.bindings.push({ event: event, callback: callback });
}
}, {
key: "off",
value: function off(event) {
this.bindings = this.bindings.filter(function (bind) {
return bind.event !== event;
});