Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How to refresh a collection?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Asa Ayers  
View profile  
 More options Sep 14 2012, 9:50 am
From: Asa Ayers <asa.ay...@gmail.com>
Date: Fri, 14 Sep 2012 06:50:58 -0700 (PDT)
Local: Fri, Sep 14 2012 9:50 am
Subject: How to refresh a collection?

I have a collection that I'd like to refresh from the server, but a simple
collection.fetch() resets the collection briefly causing all of my related
views to get destroyed and recreated. I tried collection.fetch({add: true})which solves the issue of my views getting destroyed and recreated, but if
the server passes back updated data for an existing model it doesn't get
updated. Is there something i'm missing that isn't a reset, but instead
will make the same call to the server and update all of my models?

As a temporary solution I'm using collection.fetch({add: true}) and then collection.each(function(model)
{ model.fetch() }), which works for all situations except a model being
removed, but for 10 models it requires 11 round trips to the server and
fetches all of the same data twice.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Doctor Hogart  
View profile  
 More options Sep 14 2012, 10:18 am
From: Doctor Hogart <doctor.hog...@gmail.com>
Date: Fri, 14 Sep 2012 18:18:38 +0400
Local: Fri, Sep 14 2012 10:18 am
Subject: Re: [backbonejs] How to refresh a collection?

I had same problem and this is my solution.
I have 2 collections. One is only for rendering and doesn't have even have
url property. Second have it and I call it's .fetch method when needed.
When this second collection triggers reset, I search for new models (which
are in second collection but not in first) and for deleted (which are in
first collection, but not in second).
Since I only check if there are new or deleted models, it is quite fast. If
you need to check if some models changed, it would take longer.
On Sep 14, 2012 5:51 PM, "Asa Ayers" <asa.ay...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alistair K Macdonald  
View profile  
 More options Sep 15 2012, 5:51 am
From: Alistair K Macdonald <alistair.k.macdon...@gmail.com>
Date: Sat, 15 Sep 2012 02:51:20 -0700 (PDT)
Local: Sat, Sep 15 2012 5:51 am
Subject: Re: [backbonejs] How to refresh a collection?

If you are not polling the server for changes made by other users and instead are just redrawing your collection to reflect changes made by the current user then I would recommend not polling the server, just add items to the dom in response to successful saves on models, and deletes or updates of course. Doing a server fetch can also be done as a diff, use a cached collection for your views and compare what you quietly fetch onto a temp collection not bound to any views, if it differs then redraw your views by swapping the fetched collection into your cached one which should trigger a change event.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexander Dorofeev  
View profile  
 More options Sep 22 2012, 12:28 am
From: Alexander Dorofeev <aka.s...@gmail.com>
Date: Fri, 21 Sep 2012 21:28:57 -0700 (PDT)
Local: Sat, Sep 22 2012 12:28 am
Subject: Re: How to refresh a collection?

Check `HEAD` on github. In `HEAD` version, `fetch` has `{merge: true}`parameter.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Asa Ayers  
View profile  
 More options Sep 24 2012, 8:32 am
From: Asa Ayers <asa.ay...@gmail.com>
Date: Mon, 24 Sep 2012 05:32:01 -0700 (PDT)
Local: Mon, Sep 24 2012 8:32 am
Subject: Re: [backbonejs] How to refresh a collection?

Thanks for the suggestions. My hack of a solution was to use .fetch({ add:
true, success: function(collection, response) { ... } }) and my success
handler loops over the collection deleting anything not found in the
response. I'll probably try this cached collection idea, my implementation
requires knowledge of how to parse the response from the server, so it's
not going to be portable between projects.

On Saturday, September 15, 2012 5:51:20 AM UTC-4, Alistair K Macdonald
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tanushree  
View profile  
 More options Sep 25 2012, 4:49 am
From: tanushree <tanushree.jin...@gmail.com>
Date: Tue, 25 Sep 2012 01:49:54 -0700 (PDT)
Local: Tues, Sep 25 2012 4:49 am
Subject: Re: [backbonejs] How to refresh a collection?

I've extended Backbone collection with the method described here:  
https://github.com/dalyons/backbone/commit/0af0e23ba52eaccf2a30869c06...

Now when you do a collection.fetch with {update: true}, existing models are
updated, new ones added and those deleted are removed. It works pretty
well.

Here's a related discussion on github about adding this functionality in
Backbone: https://github.com/documentcloud/backbone/issues/137


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »