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

Release 0.8.1 defaults #390

Merged
merged 3 commits into from
Aug 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dist/angularfire.js
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,14 @@ if ( typeof Object.getPrototypeOf !== "function" ) {
angular.extend(rec, data);
rec.$priority = snap.getPriority();

if( angular.isObject(rec.$$defaults) ) {
angular.forEach(rec.$$defaults, function(v,k) {
if( !rec.hasOwnProperty(k) ) {
rec[k] = v;
}
});
}

return !angular.equals(oldData, rec) ||
oldData.$value !== rec.$value ||
oldData.$priority !== rec.$priority;
Expand Down
2 changes: 1 addition & 1 deletion dist/angularfire.min.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@
angular.extend(rec, data);
rec.$priority = snap.getPriority();

if( angular.isObject(rec.$$defaults) ) {
angular.forEach(rec.$$defaults, function(v,k) {
if( !rec.hasOwnProperty(k) ) {
rec[k] = v;
}
});
}

return !angular.equals(oldData, rec) ||
oldData.$value !== rec.$value ||
oldData.$priority !== rec.$priority;
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ describe('$firebaseUtils', function () {
expect($utils.updateRec(rec, testutils.snap({foo: 'bar'}, 'foo'))).toBe(false);
});

// save this for the next PR
xit('should add $$defaults if they exist', function() {
it('should add $$defaults if they exist', function() {
var rec = { foo: 'bar' };
rec.$$defaults = { foo: 'not_applied', bar: 'foo' };
rec.$$defaults = { baz: 'not_applied', bar: 'foo' };
$utils.updateRec(rec, testutils.snap({baz: 'bar'}));
expect(rec).toEqual(jasmine.objectContaining({foo: 'bar', bar: 'foo', baz: 'bar', $$defaults: { foo: 'not_applied', bar: 'foo' }}));
expect(rec).toEqual(jasmine.objectContaining({bar: 'foo', baz: 'bar'}));
});

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