Chris Muench
Chris Muench

Reputation: 18328

Backbone 1.0 reset vs sync event

PgaPlayersApp.AppView = Backbone.View.extend({
    el: '#pga_players_profile_app',
    initialize: function()
    {
        //Should I do 1?
        this.listenTo(PgaPlayersApp.Players, 'sync', this.addAll);

        //Should I do 2?
        this.listenTo(PgaPlayersApp.Players, 'reset', this.addAll);

        PgaPlayersApp.Players.fetch({reset: true});
    }
});

In the above code example, what is the preferred method for listening to a fetch for a collection? (sync or reset)

Upvotes: 7

Views: 1432

Answers (1)

Peter Lyons
Peter Lyons

Reputation: 146084

You should listen for 'sync'. This is the event fired on a successful fetch operation. A 'reset' is now only fired when an explicit collection.reset(newModels) is called. 'sync' is consistent between collections and models now, which is a nice consistency.

FYI: http://documentcloud.github.io/backbone/docs/backbone.html#section-93

Upvotes: 2

Related Questions