|
134 | 134 | */ |
135 | 135 | $save: function(indexOrItem) { |
136 | 136 | 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); |
139 | 140 | 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 | + }); |
141 | 146 | } |
142 | 147 | else { |
143 | 148 | return $firebaseUtils.reject('Invalid record; could determine its key: '+indexOrItem); |
|
600 | 605 | } |
601 | 606 | // be sure to do this after setting up data and init state |
602 | 607 | 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}); |
604 | 609 | }); |
605 | 610 | } |
606 | 611 | }; |
|
615 | 620 | * @returns a promise which will resolve after the save is completed. |
616 | 621 | */ |
617 | 622 | $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 | + }); |
619 | 629 | }, |
620 | 630 |
|
621 | 631 | /** |
@@ -1714,6 +1724,14 @@ if ( typeof Object.getPrototypeOf !== "function" ) { |
1714 | 1724 | angular.extend(rec, data); |
1715 | 1725 | rec.$priority = snap.getPriority(); |
1716 | 1726 |
|
| 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 | + |
1717 | 1735 | return !angular.equals(oldData, rec) || |
1718 | 1736 | oldData.$value !== rec.$value || |
1719 | 1737 | oldData.$priority !== rec.$priority; |
|
0 commit comments