Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone 1.0 reset vs sync event

Tags:

backbone.js

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)

like image 509
Chris Muench Avatar asked Jun 12 '13 19:06

Chris Muench


1 Answers

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

like image 111
Peter Lyons Avatar answered Nov 12 '22 00:11

Peter Lyons