Giter Club home page Giter Club logo

Comments (7)

petebacondarwin avatar petebacondarwin commented on June 5, 2024

You should probably be doing this by simply destroying the scope on which
you have created the binding.

On 12 April 2013 17:30, Alexandre Bourget [email protected] wrote:

I bind a "$scope.data" to angularFire, using the normal method, inside a
Controller.

From that point on, any change to data will get reflected to a certain
location in Firebase.

At some point, I have a select box to switch profile, so I replace datawith a "new" profile. I would like to be able to unwatch the previous one,
because I'm now changing the location
of the data in Firebase (to a different profile, thus a different URL).

Right now, if I call angularFire() again, with $scope and data, it'll add
a second set of watches, and write to BOTH locations.. which becomes
increasingly odd :)

Also, right now if I try to remove or replace my data element, it deletes
on the Firebase side.. which isn't very nice once I'm done editing.

To attempt to fix this, I added a way to remove watches by tweaking the
call to $watch this way:

var unwatch = $scope.$watch(name, function() {
if (self._initial) {
self._initial = false;
return;
}
var val = JSON.parse(angular.toJson($scope[name]));
if (angular.equals(val, self._remoteValue)) {
return;
}
self.fRef.set(val);
}, true);
$scope['$ngFireUnwatch
' + name] = unwatch;

First and last lines are important here.

So I manage to be able to remove the watches from my code, before calling
angularFire again.. and it works the first or second time I switch.. but
then it completely deletes my objects from Firebase.

How could we solve this elegantly ?

thanks for your great work


Reply to this email directly or view it on GitHubhttps://github.com//issues/13
.

from angularfire.

abourget avatar abourget commented on June 5, 2024

But I get another kind of problem.. it's that the fRef inside the angularFire keeps those fRef.on('value') bound.. and that's what's causing problems afterwards..

It seems that Firebase is kind of keeping a cache of those URLs we're passing through.. so keeps the hooks up if you come back and call angularFire() another time with the same URL..

So I kind of fixed it with:

$scope['$ngFireUnwatch_' + name] = function() {
  self._fRef.off('value');
  unwatch();
}

otherwise, it was deleting my things.

I thought of using the $scope.. but then my controller,s scope has other uses.. and I can't clean it up just to trigger one mechanism. And also.. I think the problem would persist, because it goes inside Firebase.. and its caching system (didn't look there though).

from angularfire.

petebacondarwin avatar petebacondarwin commented on June 5, 2024

AngularFire should be listening to the $destroy event on the scope to which
it is associated to do the unbinding.
If you are needing to bind and unbind values then I would, personally be
creating a new scope for this. This is what inherited scopes are for.
Just have another controller within the controller that you are currently
using.
Pete

On 12 April 2013 18:11, Alexandre Bourget [email protected] wrote:

But I get another kind of problem.. it's that the fRef inside the
angularFire keeps those fRef.on('value') bound.. and that's what's causing
problems afterwards..

It seems that Firebase is kind of keeping a cache of those URLs we're
passing through.. so keeps the hooks up if you come back and call
angularFire() another time with the same URL..

So I kind of fixed it with:

$scope['$ngFireUnwatch_' + name] = function() {
self._fRef.off('value');
unwatch();
}

otherwise, it was deleting my things.

I thought of using the $scope.. but then my controller,s scope has other
uses.. and I can't clean it up just to trigger one mechanism. And also.. I
think the problem would persist, because it goes inside Firebase.. and its
caching system (didn't look there though).


Reply to this email directly or view it on GitHubhttps://github.com//issues/13#issuecomment-16305054
.

from angularfire.

abourget avatar abourget commented on June 5, 2024

Hmm.. yeah.. and angularFire isn't even listening to $destroy as I can see.. and upon $destroy-ction, if should _fRef.off('value') to make sure it's detached from Firebase too.

Anyway.. I've got something semi-working here.. I'll probably push to my branch if I'm satisfied a bit later. Maybe this will need more reflection.

from angularfire.

petebacondarwin avatar petebacondarwin commented on June 5, 2024

We should certainly be adding handling $destroy.

On 12 April 2013 18:33, Alexandre Bourget [email protected] wrote:

Hmm.. yeah.. and angularFire isn't even listening to $destroy as I can
see.. and upon $destroy-ction, if should _fRef.off('value') to make sure
it's detached from Firebase too.

Anyway.. I've got something semi-working here.. I'll probably push to my
branch if I'm satisfied a bit later. Maybe this will need more reflection.


Reply to this email directly or view it on GitHubhttps://github.com//issues/13#issuecomment-16306275
.

from angularfire.

anantn avatar anantn commented on June 5, 2024

Good catch @abourget - as @petebacondarwin suggests handling $destory would be a great start.

from angularfire.

anantn avatar anantn commented on June 5, 2024

FWIW, you can also use the disassociate callback provided to the promise on resolution (added via pull request #34).

from angularfire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.