examples/todos/js/backbonefire.js
function(snap) {
          var model = Backbone.Firebase._checkId(snap);

          var item = _.find(this.models, function(child) {
            return child.id == model.id;
          });

          if (!item) {
            // TODO: Investigate: what is the right way to handle this case?
            //throw new Error('Could not find model with ID ' + model.id);
            this._childAdded(snap);
            return;
          }

          this._preventSync(item, true);
          item._remoteAttributes = model;

          // find the attributes that have been deleted remotely and
          // unset them locally
          var diff = _.difference(_.keys(item.attributes), _.keys(model));
          _.each(diff, function(key) {
            item.unset(key);
          });

          item.set(model);
          // fire sync since this is a response from the server
          this.trigger('sync', this);
          this._preventSync(item, false);
        }
function(snap) {
          var model = Backbone.Firebase._checkId(snap);

          var item = _.find(this.models, function(child) {
            return child.id == model.id;
          });

          if (!item) {
            // TODO: Investigate: what is the right way to handle this case?
            //throw new Error('Could not find model with ID ' + model.id);
            this._childAdded(snap);
            return;
          }

          this._preventSync(item, true);
          item._remoteAttributes = model;

          // find the attributes that have been deleted remotely and
          // unset them locally
          var diff = _.difference(_.keys(item.attributes), _.keys(model));
          _.each(diff, function(key) {
            item.unset(key);
          });

          item.set(model);
          // fire sync since this is a response from the server
          this.trigger('sync', this);
          this._preventSync(item, false);
        }
function ( snap ) { var model = Backbone . Firebase . _checkId ( snap ) ; var item = _ . find ( this . models , function ( child ) { return child . id == model . id ; } ) ; if ( ! item ) { // TODO: Investigate: what is the right way to handle this case? //throw new Error('Could not find model with ID ' + model.id); this . _childAdded ( snap ) ; return ; } this . _preventSync ( item , true ) ; item . _remoteAttributes = model ; // find the attributes that have been deleted remotely and // unset them locally var diff = _ . difference ( _ . keys ( item . attributes ) , _ . keys ( model ) ) ; _ . each ( diff , function ( key ) { item . unset ( key ) ; } ) ; item . set ( model ) ; // fire sync since this is a response from the server this . trigger ( 'sync' , this ) ; this . _preventSync ( item , false ) ; }
when a model has changed remotely find differences between the local and remote data and apply them to the local model
when a model has changed remotely find differences between the local and remote data and apply them to the local model