What is the reason that $destroy() exists in Angularfire?
The documentation of angularfire sais:
https://www.firebase.com/docs/web/libraries/angular/api.html#angularfire-firebasearray-destroy
Stop listening for events and free memory used by this array (empties the local copy). Changes are no longer synchronized to or from Firebase.
sync = $firebase(ref).$asArray();
...
....
sync.$destroy()
Can I not just do:
sync = null
or
delete sync
Or should I really use $destroy() for some reason?
The $destroy()
exists to empty the data and unbind event listeners. If you need to unbind the $firebaseArray()
or $firebaseObject()
you could use $destroy()
but I think it would be nicer to use the unbind function that is resolved.
This was code snippet was taken from angularfire-seed
var unbind;
// create a 3-way binding with the user profile object in Firebase
var profile = $firebaseObject(fbutil.ref('users', user.uid));
profile.$bindTo($scope, 'profile').then(function(ub) { unbind = ub; });
// expose logout function to scope
$scope.logout = function() {
if( unbind ) { unbind(); }
profile.$destroy();
...
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With