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

Commit 056f89c

Browse files
committed
Fixes #372 - add defaults to records; added as $$defaults, docs to be revised.
1 parent 594b834 commit 056f89c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@
214214
angular.extend(rec, data);
215215
rec.$priority = snap.getPriority();
216216

217+
if( angular.isObject(rec.$$defaults) ) {
218+
angular.forEach(rec.$$defaults, function(v,k) {
219+
if( !rec.hasOwnProperty(k) ) {
220+
rec[k] = v;
221+
}
222+
});
223+
}
224+
217225
return !angular.equals(oldData, rec) ||
218226
oldData.$value !== rec.$value ||
219227
oldData.$priority !== rec.$priority;

tests/unit/utils.spec.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,11 @@ describe('$firebaseUtils', function () {
6262
expect($utils.updateRec(rec, testutils.snap({foo: 'bar'}, 'foo'))).toBe(false);
6363
});
6464

65-
// save this for the next PR
66-
xit('should add $$defaults if they exist', function() {
65+
it('should add $$defaults if they exist', function() {
6766
var rec = { foo: 'bar' };
68-
rec.$$defaults = { foo: 'not_applied', bar: 'foo' };
67+
rec.$$defaults = { baz: 'not_applied', bar: 'foo' };
6968
$utils.updateRec(rec, testutils.snap({baz: 'bar'}));
70-
expect(rec).toEqual(jasmine.objectContaining({foo: 'bar', bar: 'foo', baz: 'bar', $$defaults: { foo: 'not_applied', bar: 'foo' }}));
69+
expect(rec).toEqual(jasmine.objectContaining({bar: 'foo', baz: 'bar'}));
7170
});
7271

7372
it('should apply changes to record', function() {

0 commit comments

Comments
 (0)