Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 42dd317

Browse files
committed
Add $update method, fixes #238
1 parent 9817c4f commit 42dd317

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

angularfire.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,27 @@
241241
return deferred.promise;
242242
};
243243

244+
// Non-destructively update only a subset of keys for the current object.
245+
// This is the equivalent of calling `update()` on a Firebase reference.
246+
// Takes a single mandatory argument:
247+
//
248+
// * `newValue`: The set of keys and values that must be updated for
249+
// this location.
250+
//
251+
// This function returns a promise that will be resolved when the data
252+
// has been successfully saved to the server.
253+
object.$update = function(newValue) {
254+
var deferred = self._q.defer();
255+
self._fRef.ref().update(self._parseObject(newValue), function(err) {
256+
if (err) {
257+
deferred.reject(err);
258+
} else {
259+
deferred.resolve();
260+
}
261+
});
262+
return deferred.promise;
263+
};
264+
244265
// Update a value within a transaction. Calling this is the
245266
// equivalent of calling `transaction()` on a Firebase reference.
246267
//

angularfire.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/e2e/test_chat.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,33 @@ casper.then(function() {
8888
});
8989
});
9090

91+
casper.then(function() {
92+
var _testName = "GuestTest";
93+
var _testMessage = "Modified test message";
94+
95+
this.evaluate(function(params) {
96+
window.__flag = false;
97+
var idx = _scope.messages.$getIndex();
98+
var key = idx[idx.length-1];
99+
var obj = {}; obj[key] = {from: params[0], content: params[1]};
100+
_scope.messages.$update(obj).then(function() {
101+
window.__flag = true;
102+
});
103+
}, [_testName, _testMessage]);
104+
105+
this.waitFor(function() {
106+
return this.getGlobal("__flag") === true;
107+
}, function() {
108+
this.test.assertEval(function(params) {
109+
var msgs = document.querySelectorAll(".messageBlock");
110+
if (msgs.length != 2) {
111+
return false;
112+
}
113+
return testIfInDOM(params[0], params[1], msgs[1]);
114+
}, "Testing if $update works", [_testName, _testMessage]);
115+
});
116+
});
117+
91118
casper.then(function() {
92119
this.test.assertEval(function() {
93120
_scope.message = "Limit Test";

0 commit comments

Comments
 (0)