Skip to content

Instantly share code, notes, and snippets.

@katowulf
Last active September 14, 2017 20:29
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save katowulf/f264e7e0c7b8cefd1bcf to your computer and use it in GitHub Desktop.
Save katowulf/f264e7e0c7b8cefd1bcf to your computer and use it in GitHub Desktop.
Decorate $firebaseArray to provide a destroy function.
(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();
});
};
});
})();
@RyanWarner
Copy link

How would this be done for a $firebaseObject?

@meetbryce
Copy link

@RyanWarner - I ended up figuring it out and had to support both $firebaseObject and $firebaseArray - https://gist.github.com/meetbryce/614104cf5b09f2a868b399b29a1e20fa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment