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

Commit c9de214

Browse files
committed
Prevent loaded event from being called multiple times, fixes #237
1 parent 10d2d1b commit c9de214

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

angularfire.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,12 @@
431431
}
432432
}
433433

434+
// Call handlers for the "loaded" event.
435+
if (self._loaded !== true) {
436+
self._loaded = true;
437+
self._broadcastEvent("loaded", value);
438+
}
439+
434440
switch (typeof value) {
435441
// For primitive values, simply update the object returned.
436442
case "string":
@@ -440,20 +446,16 @@
440446
break;
441447
// For arrays and objects, switch to child methods.
442448
case "object":
449+
self._fRef.off("value", gotInitialValue);
443450
// Before switching to child methods, save priority for top node.
444451
if (snapshot.getPriority() !== null) {
445452
self._updateModel("$priority", snapshot.getPriority());
446453
}
447454
self._getChildValues();
448-
self._fRef.off("value", gotInitialValue);
449455
break;
450456
default:
451457
throw new Error("Unexpected type from remote data " + typeof value);
452458
}
453-
454-
// Call handlers for the "loaded" event.
455-
self._loaded = true;
456-
self._broadcastEvent("loaded", value);
457459
};
458460

459461
self._fRef.on("value", gotInitialValue);
@@ -620,7 +622,7 @@
620622
// If the new local value matches the current remote value, we don't
621623
// trigger a remote update.
622624
var local = self._parseObject(self._parse(name)(scope));
623-
if (self._object.$value &&
625+
if (self._object.$value !== undefined &&
624626
angular.equals(local, self._object.$value)) {
625627
return;
626628
} else if (angular.equals(local, self._parseObject(self._object))) {

angularfire.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)