Skip to content
This repository was archived by the owner on Feb 12, 2021. It is now read-only.

Add window-events#501

Open
f-elix wants to merge 1 commit intoDeuxHuitHuit:masterfrom
f-elix:window-events
Open

Add window-events#501
f-elix wants to merge 1 commit intoDeuxHuitHuit:masterfrom
f-elix:window-events

Conversation

@f-elix
Copy link

@f-elix f-elix commented Oct 30, 2020

window-events.js aims to eventually replace site-notifier.js.

Like site-notifier.js, it is made to centralize all window events in one place to avoid having the same event registered multiple times by various modules, improving global performance.

The difference is that no event is registered until at least one module registers it, so it is a bit more economical. It is also more flexible. Finally, site-notifier has to notify the whole array of modules (which can get quite large), whereas window-events only has to through the handlers associated with one event, which is bound to be faster.

Usage:

App.fx.notify('window.on', {
event: 'resize',
handler: onResize
});

In this case, window-events.js checks if the 'resize' event is already registered. If it is, it will add the handler to an array of handlers. If not, it will create a 'resize' property in the listeners object and initiate a new array with the handler in it.

To remove the listener:

App.fx.notify('window.off', {
event: 'resize',
handler: onResize
});

window-events.js will remove the handler, and if no other handler is present for this event after that, the event will be unregistered from the window.

@f-elix f-elix self-assigned this Oct 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant