-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Provide Backbone Model/Collection as first parameter to jQuery Deferred callbacks #1774
Comments
Hi @pmaccart! Is there any reason you can't use the |
We started off using those, but at the scale our our application (upwards of 10 layers of nested Backbone views in most cases), it became very unwieldy to supply the models/collections all the way down through the views, as well as keeping track of what particular models/collections had been fetched. We've been experimenting with the deferred pattern and have found it much more pleasant to code against, particularly in cases where a single view requires multiple models:
This pattern works great when a single view is managing the collections, but when lots of nested views rely in different combinations of the data to render, things break down. It'd be much cleaner to be able to provide the deferred for a fetch, then trust the collection/model the fetch was invoked upon would be provided to the callbacks. Will have a pull request in shortly... |
Closing this; pull request created issue #1775. I'm still working on polishing my GitHub skills... |
If all you need is just model in fulfillment handler of your promise you can take a look on my single-line plugin ;) |
Hi all,
We've been leveraging the Deferred objects returned from Backbone.sync calls extensively in our application, and have found those to be very convenient, particularly when views depend on multiple models.
One case we've struggled with is when we have nested Backbone views, we're forced to provide both the collection instance and deferred object to the child view constructor:
The example above is fairly trivial, but quickly becomes complex has the hierarchy grows (particularly if certain views in the hierarchy should not be blocked from rendering based on data not being ready). It would be nice if the deferred would be modified slightly such that the collection (or model) was provided as the first argument to the callbacks:
I've attached a pull request to this issue illustrating a potential fix, but am certainly open to suggestions and other approaches to take.
Thanks,
Phil
The text was updated successfully, but these errors were encountered: