This repository has been archived by the owner on Feb 12, 2021. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.