2015-01-28 18 views
11

Jaki jest powód, że $ destroy() istnieje w Angularfire?

Dokumentacja angularfire NOK:

https://www.firebase.com/docs/web/libraries/angular/api.html#angularfire-firebasearray-destroy

przestać słuchać na imprezach i wolnej pamięci używanych przez tej tablicy (opróżnia lokalną kopię). Zmiany nie są już synchronizowane z Firebase ani z niego.

sync = $firebase(ref).$asArray(); 
... 
.... 
sync.$destroy() 

nie mogę po prostu zrobić:

sync = null 

lub

delete sync 

Albo mam naprawdę użyć $ zniszczyć() z jakiegoś powodu?

+0

[Patrząc na linii] (https://github.com/firebase/angularfire/blob/master/src/FirebaseObject.js#L133) IT wydaje się, że nie musisz nawet wywoływać $ destroy, jeśli niszczysz zakres. Jeśli nie niszczysz zakresu, powinieneś zrobić coś podobnego do [this] (https://github.com/firebase/angularfire-seed/blob/master/app/account/account.js#L8-L19) –

Odpowiedz

4

$destroy()exists to empty the data and unbind event listeners. Jeśli trzeba rozwiązać ten $firebaseArray() lub $firebaseObject() można użyć $destroy() ale myślę, że byłoby ładniej użyć funkcji Unbind że został rozwiązany.

To fragment kodu pobrano z 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(); 
    ... 
    }; 
Powiązane problemy