Skip to content

Commit

Permalink
Merge b587e18 into 9fdffec
Browse files Browse the repository at this point in the history
  • Loading branch information
katowulf committed Nov 13, 2014
2 parents 9fdffec + b587e18 commit 4bf4f3d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/FirebaseObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,19 @@
* Called by $firebase whenever an item is changed at the server.
* This method must exist on any objectFactory passed into $firebase.
*
* @param snap
* It should return true if any changes were made, otherwise `$$notify` will
* not be invoked.
*
* @param {object} snap a Firebase snapshot
* @return {boolean} true if any changes were made.
*/
$$updated: function (snap) {
// applies new data to this object
var changed = $firebaseUtils.updateRec(this, snap);
// applies any defaults set using $$defaults
$firebaseUtils.applyDefaults(this, this.$$defaults);
if( changed ) {
// notifies $watch listeners and
// updates $scope if bound to a variable
this.$$notify();
}
// returning true here causes $$notify to be triggered
return changed;
},

/**
Expand All @@ -225,8 +227,8 @@
},

/**
* Updates any bound scope variables and notifies listeners registered
* with $watch any time there is a change to data
* Updates any bound scope variables and
* notifies listeners registered with $watch
*/
$$notify: function() {
var self = this, list = this.$$conf.listeners.slice();
Expand Down
9 changes: 8 additions & 1 deletion src/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,14 @@
var obj = new ObjectFactory($inst, destroy, def.promise);
var ref = $inst.$ref();
var batch = $firebaseUtils.batch();
var applyUpdate = batch(obj.$$updated, obj);
var applyUpdate = batch(function(snap) {
var changed = obj.$$updated(snap);
if( changed ) {
// notifies $watch listeners and
// updates $scope if bound to a variable
obj.$$notify();
}
});
var error = batch(obj.$$error, obj);
var resolve = batch(_resolveFn);

Expand Down
1 change: 1 addition & 0 deletions tests/unit/FirebaseObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ describe('$FirebaseObject', function() {
$timeout.flush();
$fb.$set.calls.reset();
obj.$$updated(fakeSnap({foo: 'bar'}));
obj.$$notify();
flushAll();
expect($scope.test).toEqual({foo: 'bar', $id: obj.$id, $priority: obj.$priority});
});
Expand Down

0 comments on commit 4bf4f3d

Please sign in to comment.