-
Notifications
You must be signed in to change notification settings - Fork 20.6k
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
Improve when/then for non-ajax usage #2545
Comments
Your example is incorrect; Also, jQuery 3's Deferred follow the Promises/A+ spec which mandates that A working example: http://jsfiddle.net/0r62we79/1/. |
I've improved the example further and must still argue that the first I understand that a Notice it shows EDIT: http://jsfiddle.net/0r62we79/3/ ok, so not passing anything to |
The new example is still incorrect. The value passed to |
@scottgonzalez @mzgol why in one instance should I return a Promise and in the next I should return a function? Obviously In this example I remove jQuery from the equation: http://jsfiddle.net/0r62we79/4/ See how much cleaner the original spec code is? I want the most simple, cross-browser solution possible, is there anything I can change in my example to simplify it with jQuery? |
This is not a direct equivalent of the jQuery version, this is: http://jsfiddle.net/0r62we79/5/
Of course, if you know a promise you get is the kind of promise you use in your code, you don't need the conversion step and it's enough to attach On the other hand, I'm afraid we're entering Stack Overflow area, though; please search further help here as there's definitely no bug in jQuery reported here. The concepts that you struggle with are required to comprehend to be able to write any promise-based code, not only using jQuery but also using standard promises. One of the resources you might want to read that should be pretty comprehensive is You Don't Know JS - Chapter 3: Promises. |
To finish - the only thing I see that's currently wrong here is that AFAIK |
@mzgol great answers, thank you! I'll keep an eye on #2018. If that issue is addressing your example here: http://jsfiddle.net/0r62we79/9/ then it will cover the exact problem I was having. The idea that Thanks again! |
@krazyjakee OK, #2018 has apparently not covered that issue, #2546 is. So we've discovered a bug in |
@mzgol sorry I couldn't be more direct with my descriptions. As you can see, I'm just starting to make use of these new features of javascript. Thanks again. |
The following code is a simple example of then chaining as I would expect it to work. In the documentation here: https://api.jquery.com/jquery.when/ the way $.Deferred is used in the non-ajax example does not explain how I should structure the code below. It also makes the code so complicated and ugly, I may as well use traditional callbacks to clean up. My suggestion is to let "then" handle a javascript promise as expected below.
The result is that both synchronous functions fire instantly instead of waiting for the previous async promises to resolve.
http://jsfiddle.net/0r62we79/
In addition, if a promise is not returned, the next "then" function should be called immediately. Then I can unwrap the function from it's promise in functionSync.
I and many others are struggling with the bizarre terminology, workflow and ugly code of the when feature. Even if I have misunderstood everything, the documentation needs to be improved.
The text was updated successfully, but these errors were encountered: