Closed graulund closed 8 years ago
Hi @graulund ! Thanks for your feedback. Yes, it seems like something is amiss here and that we should be able to fix it.
Can you please specify how exactly the collection is being reloaded from the server?
I was simply doing it using a fetch()
on the collection. :)
Hi Andy,
What version of backbone were you using?
Thx!
On Tue, Dec 8, 2015 at 2:44 AM, Andy Graulund notifications@github.com wrote:
I was simply doing it using a fetch() on the collection. :)
— Reply to this email directly or view it on GitHub https://github.com/rotundasoftware/backbone.collectionView/issues/68#issuecomment-162846111 .
Newest version. 1.2.3.
Hi Andy,
Looks like the default fetch
implementation calls set
, which ends up firing a remove
event for each model that is removed, and can cause those selectionChanged
events to get fired. That seems like expected behavior to me from the perspective of the collection view.. the weird part is in backbone. Fortunately, from looking at the backbone fetch
code,
fetch: function(options) {
options = _.extend({parse: true}, options);
var success = options.success;
var collection = this;
options.success = function(resp) {
var method = options.reset ? 'reset' : 'set';
collection[method](resp, options);
if (success) success.call(options.context, collection, resp, options);
collection.trigger('sync', collection, resp, options);
};
wrapError(this, options);
return this.sync('read', this, options);
},
I think you should be able to work around the issue by passing { reset : true }
to as an option to fetch
(or { silent : true }
, but then you would need to explicitly re-render the collection view).
Closing for now. Let me know if that does not work for your needs!
Thx!
This is not an entirely objective point of view, so I understand if you won't fix it.
When I have a collection in the view that I reload completely from the server, the following line in the code causes the
collectionView
to fire as many"selectionChanged"
events as there are items in the list, resulting in a ton of event calls every time the list is reloaded, events that could be mistaken as legit user clicks in the list.https://github.com/rotundasoftware/backbone.collectionView/blob/master/src/backbone.collectionView.js#L610
I appreciate how this line works when only one or two elements are removed, however I propose that a way is needed to disable this line in the code, or to do something that works around the consequences when the entire collection is reloaded.
Thanks! :)