-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ready.js could deduplicate readystate listener by target #65
Comments
@klebba — what would you think about just not having |
@theengineear I think |
I'm ok to leave it in if the intention is that it will be replaced with platform-level behavior. Perhaps one action item would be to document that fact in the code. |
@klebba — Just looking to follow-up on some issues in this repo. Do you have an example of when we would use // This functionality can be replaced by the "document.loaded" which will be
// introduced in https://github.com/whatwg/html/pull/1936.
const documentLoadedPromise = new Promise(resolve => {
if (document.readyState === 'complete') {
resolve();
} else {
const handle = () => {
if (document.readyState === 'complete') {
document.removeEventListener('readystatechange', handle);
resolve();
}
};
document.addEventListener('readystatechange', handle);
}
});
const ready = () => documentLoadedPromise;
export default ready; |
I think on principal we should not assume the event target here, but I don't feel super strongly about this. If you prefer we could include something like this in the file:
|
My goal was to make the functionality in Did you have a use-case for ever passing in anything other than |
I remember needing to pass |
I don't think this would be an issue. It's going from
So by "deferring" here, this means "deduplicate readystate listener by target"? I was trying to deduplicate by simplifying, but I can build it out by maintaining a mapping instead. |
Oh yeah, you're totally right — good call. Nothing would break. What about something like:
Also to clarify, what I meant by my deferring comment is "I recommend we wait before making changes" — mostly because the browser implementations aren't yet settled. Ultimately I'm in favor of making your recommended simplification to address the initial impetus for the ticket. You are right that it's minor |
☝️ — Sure, I can make it the default. If a user passes in something other than document, shouldn't we do the right thing though? I'll put up a PR to discuss. |
the DOMReady util
ready
currently adds new event listeners every time it is invoked; instead it could create a mapping of callbacks keyed to targets and avoid making duplicate listenersref: https://github.com/Netflix/x-element/blob/82283f53d36f01ee91640818c76144cf99ecb255/etc/ready.js
The text was updated successfully, but these errors were encountered: