Created
March 16, 2016 06:33
-
-
Save xifengzhu/556b47c71445f3d61588 to your computer and use it in GitHub Desktop.
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 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