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
Update support for collections. #446
Conversation
…ns. Added update option to Collection.fetch().
I love the idea! I've added an updateInto() function to my collections that checks for the existence of each model and either adds it or updates it. The fact it works with fetch is a plus =) |
+1. Exactly what I was looking for. Thanks dude! |
+1. This can be useful to many people. |
+1 Just what I needed! |
+1 Just what I'm looking for, and came accross this issue |
+1 would be very helpful in my current project. |
+1 |
It might be a better idea to have this functionality as an option to add, like |
While removing models that wasn't in the response may not be a large use case, there are some people who could use it. Would it be too hard to have another flag/callback to remove models that weren't in the response?
Or would it be better for the whole collection to be cleared and then add models in the response? |
I'd be much happier with a removal of the models too, I can think of many use cases. A buddy list for example, when people sign off line maybe you want to remove the user from the list, grey out their chat windows, and set off any notifications that might be set for the user. I do see however that you might want this optional, so you can poll a url for only changed models and not have to pull down the entire list each time. |
Any chance of this getting accepted? I'm using 0.5.3 with this patch and it works great. |
+1 |
On line 525 you should use the methods relative to |
I'm wrong, on 525 could use the built-in. Edited. |
This is dependent on the pull request jashkenas/backbone#446
Includes: - jashkenas/backbone#569 ability to define local elements - jashkenas/backbone#446 integrate Collection.update - jashkenas/backbone#570 ability to pass a single attr/value pair in `set' and `save' - jashkenas/backbone#567 this.el being the jQuery/Zepto object
Hi dalyons, I noticed you don't have options support in this method. I wont be able to pass {silent:true} or error functions. |
This is exactly what I was looking for. I was almost considering doing
|
I merged this with in my version of backbone, but I had to remove the |
You can now call |
@jashkenas Your solution does not cover all the functionality proposed here. It certainly works for new instances created on the server, but if existing instances are updated on the server or removed, these would not be reflected on the client. A typical scenario is for any kind of polling implementation where something needs to be kept up-to-date on the client. Also the idea of having a client request what they don't have is a bit odd in practice. Of course this can be done using timestamps with respect to the last request, but it seems simpler for the client to request the whole collection and then figure out what needs updating vs. creating vs. removing to ensure client state is in sync with the server's. |
I have to agree with bruth here. This doesn't add a functionality for updating with the same request an entire collection. |
Yes, you're quite right ... |
I think that it should be included. Updating a collection is needed in nearly every kind of app using BackBone. Of course you should have the ability to update (or fetch) a particular record. But when you have a list of many objects, and need to update them all at once, iterating over the elements and applying |
+1 |
2 similar comments
+1 |
+1 |
This pull request resolves the issue described here:
#137
It adds in-place updating support for collections, which is the ability to refresh the contents of a collection without creating new model instances for models that already exist client-side.
The use case is something like this:
It works well for us. I think some flavour of this mechanism would be very useful to include in backbone, even if you think this initial implementation isn't quite right from an API pov.
Let me know what you think!