|
5 | 5 | // as normal, except that the changes are also sent to all other clients
|
6 | 6 | // instead of just a server.
|
7 | 7 | //
|
8 |
| -// AngularFire 0.7.1 |
| 8 | +// AngularFire 0.7.2-pre |
9 | 9 | // http://angularfire.com
|
10 | 10 | // License: MIT
|
11 | 11 |
|
|
645 | 645 | var self = this;
|
646 | 646 | if( self._loaded && ['child_added', 'loaded', 'value'].indexOf(evt) > -1 ) {
|
647 | 647 | self._timeout(function() {
|
648 |
| - var parsedValue = angular.isObject(self._object)? self._parseObject(self._object) : self._object; |
| 648 | + var parsedValue = self._object.hasOwnProperty('$value')? |
| 649 | + self._object.$value : self._parseObject(self._object); |
649 | 650 | switch(evt) {
|
650 | 651 | case 'loaded':
|
651 | 652 | callback(parsedValue);
|
|
711 | 712 | self._fRef.ref().update(self._parseObject(local));
|
712 | 713 | }
|
713 | 714 |
|
| 715 | + // When the scope is destroyed, unbind automatically. |
| 716 | + scope.$on("$destroy", function() { |
| 717 | + unbind(); |
| 718 | + }); |
| 719 | + |
| 720 | + // Once we receive the initial value, the promise will be resolved. |
| 721 | + self._object.$on('loaded', function(value) { |
| 722 | + self._timeout(function() { |
| 723 | + if(value === null && typeof defaultFn === 'function') { |
| 724 | + scope[name] = defaultFn(); |
| 725 | + } |
| 726 | + else { |
| 727 | + scope[name] = value; |
| 728 | + } |
| 729 | + deferred.resolve(unbind); |
| 730 | + }); |
| 731 | + }); |
| 732 | + |
714 | 733 | // We're responsible for setting up scope.$watch to reflect local changes
|
715 | 734 | // on the Firebase data.
|
716 | 735 | var unbind = scope.$watch(name, function() {
|
|
738 | 757 | }
|
739 | 758 | }, true);
|
740 | 759 |
|
741 |
| - // When the scope is destroyed, unbind automatically. |
742 |
| - scope.$on("$destroy", function() { |
743 |
| - unbind(); |
744 |
| - }); |
745 |
| - |
746 |
| - // Once we receive the initial value, the promise will be resolved. |
747 |
| - self._fRef.once("value", function(snap) { |
748 |
| - self._timeout(function() { |
749 |
| - // HACK / FIXME: Objects require a second event loop run, since we |
750 |
| - // switch from value events to child_added. See #209 on Github. |
751 |
| - if (typeof snap.val() != "object") { |
752 |
| - // If the remote value is not set and defaultFn was provided, |
753 |
| - // initialize the local value with the result of defaultFn(). |
754 |
| - if (snap.val() == null && typeof defaultFn === 'function') { |
755 |
| - scope[name] = defaultFn(); |
756 |
| - } |
757 |
| - deferred.resolve(unbind); |
758 |
| - } else { |
759 |
| - self._timeout(function() { |
760 |
| - // If the remote value is not set and defaultFn was provided, |
761 |
| - // initialize the local value with the result of defaultFn(). |
762 |
| - if (snap.val() == null && typeof defaultFn === 'function') { |
763 |
| - scope[name] = defaultFn(); |
764 |
| - } |
765 |
| - deferred.resolve(unbind); |
766 |
| - }); |
767 |
| - } |
768 |
| - }); |
769 |
| - }); |
770 |
| - |
771 | 760 | return deferred.promise;
|
772 | 761 | },
|
773 | 762 |
|
|
0 commit comments