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 listening method for a collection? (sync or reset)

+6
source share
1 answer

You must listen to 'sync' . This event was fired on a successful retrieve operation. A 'reset' now runs only when calling explicit collection.reset(newModels) . 'sync' now consistent between collections and models, which is a good consistency.

FYI: http://documentcloud.imtqy.com/backbone/docs/backbone.html#section-93

+1
source

Source: https://habr.com/ru/post/947152/


All Articles