joystick
joystick copied to clipboard
Add a way to register window-level events via the events property on a component
This just came up while working on a UI that needs window (technically, document.body) level events. These can currently be added via the onMount lifecycle event but this prevents automatic cleanup from happening via Joystick.
Proposal would be to have something like this:
events: {
window: (addEventListener) => {
addEventListener(document.body, () => {
// Handle event here.
});
},
}
The idea being that you set the events.window key to a function which is handed a function for adding your event listeners. The point being that we get a way to track the events being attached alongside other events defined on the component.