Deathslice246
At the moment, I’m using angularjs with phoenix and I want to know how can I unbind custom channel events.
In Angularjs, one way would be like this.
var unbindHandler = $scope.$on("channel_event", channelFunction); // returns a deregistration function
.... later down the line
unbindHandler() // event is unbinded
unbindHandler = null
When I try to do the same thing with with the channel object.
var unbindHandler = channel.on("new_message", message => {
... code
})
and call it
unbindHandler()
I get an error saying that unbindHandler is not a function because it is undefined. Because of this I have to assume that channel.on doesn’t return a deregistration function for me to use so I can unbind when I’m done. What can I do?
I’ve tried to leave the channel(channel.leave()) hoping that it would automatically unbind but it still doesn’t.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
voughtdq
It returns a ref:
You could create a wrapper function:
OK, so this is untested. I don’t know if it will work, but it gives you what you want (I think).
Deathslice246
Thanks for the reply, but at least with angularjs, I don’t think it returns a ref.
To verify I did this
So is there any other way to get a handler or ref to the event?
voughtdq
Ah! I know what’s wrong.
It looks like the ref logic is only available in master right now.
You can do this:
Unfortunately it means you can’t bind to the same event multiple times. You could also try getting the updated phoenix.js from master.
Deathslice246
Thanks, that worked. I figured I was only able to bind to only one event at a time considering that when I joined a different channel, the number of bindings for each channel object was off. Much appreciated.
Deathslice246
Though I have a question before I put this topic to rest.
If I do this
Down the line I bind some events to that channel object and then I do this without unbinding the events
Would it cause a memory leak for not calling channel.off on the previous channel object and initializing it with a new one? My intuition says yes but I’m not sure.
If not, then is there any point in unbinding in my case?