You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This happens whenever a one-time event handler (registered with EventsOnce) is removed by remover function (namely, from frontend code) after it has already fired (and therefore its listener is now removed.)
Consider the following example:
// Code in JS frontendconsteventRemover=EventsOnce("myEvent",()=>console.log("Event fired.");window.removeEvent=()=>eventRemover();window.emitEvent=()=>EventsEmit("emitMyEvent");
// Code in Go backendfunc (a*App) onStartup() {
runtime.EventsOn(a.Context, "emitMyEvent", func(optionalData...interface{}) {
runtime.EventsEmit(a.Context, "myEvent")
})
}
Now, when myEvent fires and removes itself, its remover function will now cause a TypeError:
This does not happen when the remover is called before event is fired:
This can be fixed pretty easily, by making a remover no-op if the listener can't be found:
function listenerOff(listener) {
const eventName = listener.eventName;
+ const listeners = eventListeners[eventName];+ if (listeners === undefined) return;
eventListeners[eventName] = eventListeners[eventName].filter((l) => l !== listener);
if (eventListeners[eventName].length === 0) {
removeListener(eventName);
}
}
The text was updated successfully, but these errors were encountered:
Wails 2.9.1
Title basically explains the issue, which occurs here:
wails/v2/internal/frontend/runtime/desktop/events.js
Lines 203 to 212 in 5cd0cac
This happens whenever a one-time event handler (registered with
EventsOnce
) is removed by remover function (namely, from frontend code) after it has already fired (and therefore its listener is now removed.)Consider the following example:
Now, when
myEvent
fires and removes itself, its remover function will now cause a TypeError:This does not happen when the remover is called before event is fired:
This can be fixed pretty easily, by making a remover no-op if the listener can't be found:
The text was updated successfully, but these errors were encountered: