Resolve returned xhr(promise) with model.#2598
Closed
tomalec wants to merge 1 commit intojashkenas:masterfrom
Closed
Resolve returned xhr(promise) with model.#2598tomalec wants to merge 1 commit intojashkenas:masterfrom
tomalec wants to merge 1 commit intojashkenas:masterfrom
Conversation
Owner
|
This is a bit too piecemeal of an approach to be merged as-is ... although thoughts on having nicer promise workflows are certainly welcome. It would also break a lot of apps. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
I have faced the need to use Promises with Backbone methods, or
Backbone.syncin general.I would really like to use model, as first argument of fulfill function.
I read problems related to #1774, #2489, and #2345.
I come with a simple idea: instead of trying to introduce Promises into entire Backbone flow, we can tune those given by jQuery (if any).
Simply, if we have Promise available, we will use it to resolve with
model, otherwise we will return xhr as we did before.Thanks to that, old non-promise apps and flows will still work, but we could use jQuery.Deferreds, Q, etc. to do what we want.
to work around
falsereturned by Model#saveor use Q, which also solves
falseissueif we need a rejection even nicer
( model.save() || Q.reject(model))So it will be tiny step towards Promises in Backbone.
I have also made it work for jQuery>1.6 with
.pipeif we need @50c8cf49ac62ef8fa9a0a4169fa6f3dba89bd7d4.