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

Commit e0e613a

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

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

dist/angularfire.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,15 @@
134134
*/
135135
$save: function(indexOrItem) {
136136
this._assertNotDestroyed('$save');
137-
var item = this._resolveItem(indexOrItem);
138-
var key = this.$keyAt(item);
137+
var self = this;
138+
var item = self._resolveItem(indexOrItem);
139+
var key = self.$keyAt(item);
139140
if( key !== null ) {
140-
return this.$inst().$set(key, $firebaseUtils.toJSON(item));
141+
return self.$inst().$set(key, $firebaseUtils.toJSON(item))
142+
.then(function(ref) {
143+
self._notify('child_changed', key);
144+
return ref;
145+
});
141146
}
142147
else {
143148
return $firebaseUtils.reject('Invalid record; could determine its key: '+indexOrItem);
@@ -600,7 +605,7 @@
600605
}
601606
// be sure to do this after setting up data and init state
602607
angular.forEach(self.$$conf.listeners, function (parts) {
603-
parts[0].call(parts[1], {event: 'updated', key: self.$id});
608+
parts[0].call(parts[1], {event: 'value', key: self.$id});
604609
});
605610
}
606611
};
@@ -615,7 +620,12 @@
615620
* @returns a promise which will resolve after the save is completed.
616621
*/
617622
$save: function () {
618-
return this.$inst().$set($firebaseUtils.toJSON(this));
623+
var notify = this.$$conf.notify;
624+
return this.$inst().$set($firebaseUtils.toJSON(this))
625+
.then(function(ref) {
626+
notify();
627+
return ref;
628+
});
619629
},
620630

621631
/**
@@ -1714,6 +1724,14 @@ if ( typeof Object.getPrototypeOf !== "function" ) {
17141724
angular.extend(rec, data);
17151725
rec.$priority = snap.getPriority();
17161726

1727+
if( angular.isObject(rec.$$defaults) ) {
1728+
angular.forEach(rec.$$defaults, function(v,k) {
1729+
if( !rec.hasOwnProperty(k) ) {
1730+
rec[k] = v;
1731+
}
1732+
});
1733+
}
1734+
17171735
return !angular.equals(oldData, rec) ||
17181736
oldData.$value !== rec.$value ||
17191737
oldData.$priority !== rec.$priority;

0 commit comments

Comments
 (0)