|
9 | 9 | // http://angularfire.com |
10 | 10 | // License: MIT |
11 | 11 |
|
12 | | -"use strict"; |
13 | | - |
14 | 12 | (function() { |
| 13 | + "use strict"; |
15 | 14 |
|
16 | 15 | var AngularFire, AngularFireAuth; |
17 | 16 |
|
|
41 | 40 | return function(input) { |
42 | 41 | var sorted = []; |
43 | 42 | if (input) { |
44 | | - if (!input.$getIndex || typeof input.$getIndex != "function") { |
| 43 | + if (!input.$getIndex || typeof input.$getIndex !== "function") { |
45 | 44 | // input is not an angularFire instance |
46 | 45 | if (angular.isArray(input)) { |
47 | 46 | // If input is an array, copy it |
|
134 | 133 | child_removed: [] |
135 | 134 | }; |
136 | 135 |
|
137 | | - if (typeof ref == "string") { |
| 136 | + if (typeof ref === "string") { |
138 | 137 | throw new Error("Please provide a Firebase reference instead " + |
139 | 138 | "of a URL, eg: new Firebase(url)"); |
140 | 139 | } |
|
191 | 190 | } |
192 | 191 | } |
193 | 192 |
|
194 | | - if (typeof item == "object") { |
| 193 | + if (typeof item === "object") { |
195 | 194 | ref = self._fRef.ref().push(self._parseObject(item), _addCb); |
196 | 195 | } else { |
197 | 196 | ref = self._fRef.ref().push(item, _addCb); |
|
307 | 306 | } |
308 | 307 | }, |
309 | 308 | applyLocally); |
310 | | - |
| 309 | + |
311 | 310 | return deferred.promise; |
312 | 311 | }; |
313 | 312 |
|
|
490 | 489 | }); |
491 | 490 |
|
492 | 491 | function _isPrimitive(v) { |
493 | | - return v === null || typeof(v) !== 'object'; |
| 492 | + return v === null || typeof(v) !== "object"; |
494 | 493 | } |
495 | 494 |
|
496 | 495 | function _initialLoad(value) { |
|
527 | 526 | // child_* listeners attached; if the data suddenly changes between an object |
528 | 527 | // and a primitive, the child_added/removed events will fire, and our data here |
529 | 528 | // will get updated accordingly so we should be able to transition without issue |
530 | | - self._fRef.on('value', function(snap) { |
| 529 | + self._fRef.on("value", function(snap) { |
531 | 530 | // primitive handling |
532 | 531 | var value = snap.val(); |
533 | 532 | if( _isPrimitive(value) ) { |
|
539 | 538 | } |
540 | 539 |
|
541 | 540 | // broadcast the value event |
542 | | - self._broadcastEvent('value', self._makeEventSnapshot(snap.name(), value)); |
| 541 | + self._broadcastEvent("value", self._makeEventSnapshot(snap.name(), value)); |
543 | 542 |
|
544 | 543 | // broadcast initial loaded event once data and indices are set up appropriately |
545 | 544 | if( !self._loaded ) { |
|
551 | 550 | // Called whenever there is a remote change. Applies them to the local |
552 | 551 | // model for both explicit and implicit sync modes. |
553 | 552 | _updateModel: function(key, value) { |
554 | | - if (value == null) { |
| 553 | + if (value === null) { |
555 | 554 | delete this._object[key]; |
556 | 555 | } else { |
557 | 556 | this._object[key] = value; |
|
622 | 621 | // If event handlers for a specified event were attached, call them. |
623 | 622 | _broadcastEvent: function(evt, param) { |
624 | 623 | var cbs = this._on[evt] || []; |
625 | | - if( evt === 'loaded' ) { |
| 624 | + if( evt === "loaded" ) { |
626 | 625 | this._on[evt] = []; // release memory |
627 | 626 | } |
628 | 627 | var self = this; |
|
635 | 634 |
|
636 | 635 | if (cbs.length > 0) { |
637 | 636 | for (var i = 0; i < cbs.length; i++) { |
638 | | - if (typeof cbs[i] == "function") { |
| 637 | + if (typeof cbs[i] === "function") { |
639 | 638 | _wrapTimeout(cbs[i], param); |
640 | 639 | } |
641 | 640 | } |
|
645 | 644 | // triggers an initial event for loaded, value, and child_added events (which get immediate feedback) |
646 | 645 | _sendInitEvent: function(evt, callback) { |
647 | 646 | var self = this; |
648 | | - if( self._loaded && ['child_added', 'loaded', 'value'].indexOf(evt) > -1 ) { |
| 647 | + if( self._loaded && ["child_added", "loaded", "value"].indexOf(evt) > -1 ) { |
649 | 648 | self._timeout(function() { |
650 | | - var parsedValue = self._object.hasOwnProperty('$value')? |
| 649 | + var parsedValue = self._object.hasOwnProperty("$value")? |
651 | 650 | self._object.$value : self._parseObject(self._object); |
652 | 651 | switch(evt) { |
653 | | - case 'loaded': |
| 652 | + case "loaded": |
654 | 653 | callback(parsedValue); |
655 | 654 | break; |
656 | | - case 'value': |
| 655 | + case "value": |
657 | 656 | callback(self._makeEventSnapshot(self._fRef.name(), parsedValue, null)); |
658 | 657 | break; |
659 | | - case 'child_added': |
| 658 | + case "child_added": |
660 | 659 | self._iterateChildren(parsedValue, function(name, val, prev) { |
661 | 660 | callback(self._makeEventSnapshot(name, val, prev)); |
662 | 661 | }); |
|
710 | 709 |
|
711 | 710 | // If the local model is an object, call an update to set local values. |
712 | 711 | var local = self._parse(name)(scope); |
713 | | - if (local !== undefined && typeof local == "object") { |
| 712 | + if (local !== undefined && typeof local === "object") { |
714 | 713 | self._fRef.ref().update(self._parseObject(local)); |
715 | 714 | } |
716 | 715 |
|
|
720 | 719 | }); |
721 | 720 |
|
722 | 721 | // Once we receive the initial value, the promise will be resolved. |
723 | | - self._object.$on('loaded', function(value) { |
| 722 | + self._object.$on("loaded", function(value) { |
724 | 723 | self._timeout(function() { |
725 | | - if(value === null && typeof defaultFn === 'function') { |
| 724 | + if(value === null && typeof defaultFn === "function") { |
726 | 725 | scope[name] = defaultFn(); |
727 | 726 | } |
728 | 727 | else { |
|
768 | 767 | function _findReplacePriority(item) { |
769 | 768 | for (var prop in item) { |
770 | 769 | if (item.hasOwnProperty(prop)) { |
771 | | - if (prop == "$priority") { |
| 770 | + if (prop === "$priority") { |
772 | 771 | item[".priority"] = item.$priority; |
773 | 772 | delete item.$priority; |
774 | | - } else if (typeof item[prop] == "object") { |
| 773 | + } else if (typeof item[prop] === "object") { |
775 | 774 | _findReplacePriority(item[prop]); |
776 | 775 | } |
777 | 776 | } |
|
822 | 821 | this._getCurrentUserDeferred = []; |
823 | 822 | this._currentUserData = undefined; |
824 | 823 |
|
825 | | - if (typeof ref == "string") { |
| 824 | + if (typeof ref === "string") { |
826 | 825 | throw new Error("Please provide a Firebase reference instead " + |
827 | 826 | "of a URL, eg: new Firebase(url)"); |
828 | 827 | } |
|
0 commit comments