backbone icon indicating copy to clipboard operation
backbone copied to clipboard

v2: Backbone.Promise

Open jridgewell opened this issue 9 years ago • 10 comments

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 from Backbone.sync.
  • removing all the options.success and options.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.

jridgewell avatar May 31 '15 22:05 jridgewell

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

tgriesser avatar May 31 '15 23:05 tgriesser

Agreed with @tgriesser (as long as the branches remain rebasable), and :+1: to adding BB.Promise

megawac avatar May 31 '15 23:05 megawac

That sounds good to me. :+1:

braddunbar avatar Jun 01 '15 00:06 braddunbar

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.

Cleod9 avatar Jul 31 '15 21:07 Cleod9

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.

jeromecovington avatar Aug 04 '15 01:08 jeromecovington

+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.

jeromecovington avatar Aug 04 '15 01:08 jeromecovington

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

godlark avatar Aug 28 '15 14:08 godlark

Have there been any further development on this?

marlun avatar Jan 05 '16 09:01 marlun

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 ?

mjeanroy avatar Jan 05 '16 10:01 mjeanroy

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.

akre54 avatar Jan 05 '16 14:01 akre54