-
-
Save katowulf/f264e7e0c7b8cefd1bcf to your computer and use it in GitHub Desktop.
Decorate $firebaseArray to provide a destroy function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 $delegate.$extend(function(ref) { | |
$delegate.call(this, ref); | |
openItems.push(this.$list); | |
return this.$list; | |
}); | |
}); | |
}); | |
app.factory('destroyAllRefs', function() { | |
return function() { | |
// when this factory is called, invoke $destroy on open refs | |
angular.forEach(openItems, function(item) { | |
item.$destroy(); | |
}); | |
}; | |
}); | |
})(); |
@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
How would this be done for a
$firebaseObject
?