Skip to content

Instantly share code, notes, and snippets.

@xifengzhu
Created March 16, 2016 06:33
Show Gist options
  • Save xifengzhu/556b47c71445f3d61588 to your computer and use it in GitHub Desktop.
Save xifengzhu/556b47c71445f3d61588 to your computer and use it in GitHub Desktop.
(function() {
// store a list of open refs
var openItems = [];
app.config(function($provide) {
// when creating a $firebaseArray, record the ref so we can destroy it later
$provide.decorator("$firebaseArray", function($delegate) {
return function(ref) {
var list = $delegate(ref);
openItems.push(list);
return list;
};
});
// when calling unauth, call destroy on all refs
$provide.decorator('$firebaseAuth', function($delegate) {
var _super = $delegate.
return $delegate;
});
});
app.factory('destroyAllRefs', function() {
return function() {
// when this factory is called, invoke $destroy on open refs
angular.forEach(openItems, function(item) {
item.$destroy();
});
};
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment