Skip to content

Commit

Permalink
Add $update method, fixes FirebaseExtended#238
Browse files Browse the repository at this point in the history
  • Loading branch information
anantn committed Feb 26, 2014
1 parent 9817c4f commit 42dd317
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
21 changes: 21 additions & 0 deletions angularfire.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,27 @@
return deferred.promise;
};

// Non-destructively update only a subset of keys for the current object.
// This is the equivalent of calling `update()` on a Firebase reference.
// Takes a single mandatory argument:
//
// * `newValue`: The set of keys and values that must be updated for
// this location.
//
// This function returns a promise that will be resolved when the data
// has been successfully saved to the server.
object.$update = function(newValue) {
var deferred = self._q.defer();
self._fRef.ref().update(self._parseObject(newValue), function(err) {
if (err) {
deferred.reject(err);
} else {
deferred.resolve();
}
});
return deferred.promise;
};

// Update a value within a transaction. Calling this is the
// equivalent of calling `transaction()` on a Firebase reference.
//
Expand Down
2 changes: 1 addition & 1 deletion angularfire.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions tests/e2e/test_chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,33 @@ casper.then(function() {
});
});

casper.then(function() {
var _testName = "GuestTest";
var _testMessage = "Modified test message";

this.evaluate(function(params) {
window.__flag = false;
var idx = _scope.messages.$getIndex();
var key = idx[idx.length-1];
var obj = {}; obj[key] = {from: params[0], content: params[1]};
_scope.messages.$update(obj).then(function() {
window.__flag = true;
});
}, [_testName, _testMessage]);

this.waitFor(function() {
return this.getGlobal("__flag") === true;
}, function() {
this.test.assertEval(function(params) {
var msgs = document.querySelectorAll(".messageBlock");
if (msgs.length != 2) {
return false;
}
return testIfInDOM(params[0], params[1], msgs[1]);
}, "Testing if $update works", [_testName, _testMessage]);
});
});

casper.then(function() {
this.test.assertEval(function() {
_scope.message = "Limit Test";
Expand Down

0 comments on commit 42dd317

Please sign in to comment.