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
Remove core/ready hard dependency on $.Deferred #1778
Comments
Also related to gh-1823 |
Hmm, I don't think this is necessary. Deferred is simply a hard dependency of core/ready. If Deferred is removed from a custom build, so core/ready should be too (which we could easily add to the Gruntfile). Those making custom builds are usually also accustomed to placing scripts at the end of the body, making core/ready wasted space. Maybe this is a docs issue instead. |
|
I used to think that too. We had this conversation a while ago and it turned out it is sufficient. Also, Deferred is an important API too. It is used internally in other areas besides core/ready. core/ready is probably the least important of them all. |
I did think of a limitation. On a very large document, you'd probably prefer to start downloading the script immediately, but still defer so the browser can download and parse the DOM in parallel. In this case, doc ready can still play a role just in case the script loads before the document is ready, but I think script loaders often have that covered. |
Ah, here is the conversation I was thinking of. That only overlaps because I don't remember finding evidence that putting scripts at the end if the body wouldn't work. |
You know what, I think I've already gone over to the other side. Sorry for the brain dump of notifications. This could be useful to users. My only question is, how do we handle the lack of native Promise in certain environments? |
Up until very recently we used to divide support tests into two parts: Now we have this second part of support tests lazy; in 2.x they have What bothers me most here is that if you do depend on core/ready and I was thinking that if you exclude Defered and not core/ready you're Michał Gołębiowski |
I think it's reasonable to focus on doing any dependency reduction just on master and not compat. How about this? When Deferred is missing we just do something simple like convert At the moment, |
Wouldn't that break the usage of |
In the current ready module there's already plumbing to handle that, although it might be complicated by |
I'd like to take a dependency-free Promise-compatible approach ( var readyFiring = 0,
readyCallbacks = [],
whenReady = function( callback ) {
readyCallbacks.push( callback );
};
jQuery.fn.ready = function( callback ) {
whenReady( callback );
return this;
};
// This could also be a thenable function if we want jQuery.ready( fn )
// ...but I don't
jQuery.ready = { then: jQuery.fn.ready };
// Suitably wired to load events, document.readyState, and holdReady
function resolveReady() {
whenReady = function( callback ) {
readyCallbacks.push( callback );
if ( !readyFiring++ ) {
while ( readyCallbacks.length ) {
callback = readyCallbacks.shift();
if ( jQuery.isFunction( callback ) ) {
// Perfect backcompat: synchronous call with context and no try/catch
// ...but we can break a bit with 3.0 if we want
callback.call( document, jQuery );
}
}
}
readyFiring--;
};
whenReady();
} And additionally:
|
All of the additionally's sound good to me. |
Oh that's a really simple way to patch things, and I like the fact it doesn't have dependencies. I agree with the extras as well. I never really liked |
Note that, for better or worse, MediaWiki currently makes use of It uses it to fire off jQuery's dom-ready handlers towards the end of </div>
<script>window.jQuery && jQuery.ready();</script>
<script>if(window.mw){
mw.loader.require( .. );
}</script>
<script src="/static/src/.."></script>
<script>if(window.mw){
mw.data.set({backendResponseTime:24,backendHost:"mw1240"});
}</script>
</body>
</html>
It solved a Firefox bug with regards to It also simplified things a little by not needing jQuery to do all its cross-browser stuff. And it served as a way to effectively bring |
@gibson042 Seems by #1778 (comment) that you have a good idea of how to do it; would you like to get this issue re-assigned to you? |
- Keeps is Promise-compatible Fixes jquerygh-1778
- Keeps it Promise-compatible Fixes jquerygh-1778
- Keeps it Promise-compatible Fixes jquerygh-1778
Originally reported by m_gol at: http://bugs.jquery.com/ticket/15174
If $.Deferred is unavailable (e.g. because it was removed via custom compilation), the core/ready implementation should fall back to the standard Promise.
Issue reported for jQuery 2.1.1
The text was updated successfully, but these errors were encountered: