Closed vicsnow closed 3 years ago
There currently isn't an unsubscribe feature but there probably should be. In your particular case, it sounds like you just need to ignore data2 events when data1 is mounted. If that's really what you want to do then potentially your listener can just test to see which component is mounted and ignore events for the hidden container. I guess I don't get why both containers are listening to each others events. Whilst I think having unsubscribe may be useful, it doesn't feel like that's the right solution for your particular problem.
Yea, okay, testing to see which component is mounted sounds like a reasonable solution. And that is an optimization anyways
I am running into this issue using react. Binding Wails.Events.On
with useEffect leads to the callback being bound multiple times, run when the component is not mounted, etc. Workarounds are possible but its very idiomatic (in react at least) to bind and unbind as part of the component lifecycle.
Any chance this could be re-opened?
Funny timing. I just added this to v2. Should be relatively easy to backport.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Description I am running a project, having appRun as frontend. There are two containers, I switch between, and both receive different events.
So I do
Wails.Events.On
when I mount the component And it seems, that I need to unsub or ignore other component's events on unmount So, like the title says, is there any way to "unsubscribe" from an event? Or I just need to have some additional backend logic, which does only one event emission at a time?Additional context It looks like this: I have
<Data1 />
and<Data2 />
containersData1
hasWails.Events.On("update_data1", ()=>{ ***update logic***})
when it's mountedData2
hasWails.Events.On("update_data2", ()=>{ ***update logic***})
when it's mounted Let's say, that<Data1/>
is currently rendered, after I did render<Data2/>
and call it's mounted method Receiving bothupdate_data1
andupdate_data2
events leads to incorrect rendering So I need to either "unsubscribe" fromupdate_data2
event on<Data2/>
unmount , or have some workaround logic, which allows emitting only one event at a time