backbone
backbone copied to clipboard
v2: Backbone.Promise
DO NOT MERGE, BREAKING CHANGE This is for the next major, v2.
Competes with #2489.
Specifically, it implements Backbone.Promise
instead of Backbone.Deferred
, so it can be easily swapped with any ES6 compatible Promise library.
This is phase 1. Phase 2 would be:
- returning a
Backbone.Promise
fromBackbone.sync
. - removing all the
options.success
andoptions.error
callbacks in favor of chained promises.- That includes transitioning from
success
callbacks to rejected promises, ie.Model#fetch
where validation fails with the server's attributes.
- That includes transitioning from
For any "major breaking change" PR's such as this #3649, #3644 or others where existing tests are being significantly altered/added it might be wise to create / PR against a 2.0 branch so it doesn't put master in a state where patch releases can't be made against the current master 1.x master.
Thoughts? /cc @braddunbar @jashkenas @akre54
Agreed with @tgriesser (as long as the branches remain rebasable), and :+1: to adding BB.Promise
That sounds good to me. :+1:
Referencing this ticket: https://github.com/jashkenas/backbone/issues/3739
I just wanted to bring the above to everyone's attention since if Promises are implemented some extra care should probably be taken to make sure that certain error()
arguments I mentioned are not lost somewhere in the promise. Otherwise I could anticipate some scary situations where devs are confused on the reason of an ajax failure when no relevant detail is provided by the Promise's error handler.
Allowing developers to handle their own polyfills is desirable in general and more forward-thinking, provided the specific polyfills that meet BB's requirements are clearly documented as such.
+1 @Cleod9 re: error handling. Inadvertently handling errors with a .catch()
without re-throwing up the Promise chain can be a huge source of debugging confusion.
I think if we want to return a promise it would be good to pass parsed response to then's callback. Read more at https://github.com/jashkenas/backbone/pull/3779
Have there been any further development on this?
Hi, it seems that Backbone plans to use promise as the return value of the sync
method in a futur major release and it's a good news :+1:
However, what about XHR abortion ? Currently, according to the official spec, it's not possible to cancel a promise, but aborting an ajax request is an important feature I guess. How will you handle this case ?
We can either wrap the promise for you, and attach an abort
method, or you can do that yourself in Backbone.ajax
. I'm inclined towards the latter, unless there's enough of a reason to add it to core.