IziFortune
IziFortune

Reputation: 99

Firebase remove strange behaviour

i have the following code in my app

this.obsRef.remove(function(error) {
      self.firebaseRef.child('users/'+self.user.name+'/invite')
               .remove(function(error) {
                    self.enterLobby();
                });
            });

What is code should do is to remove obsRef from firebase and then remove the location on 'users/$user/invite'. Once all is removed enterLobby is called.

Now the problem is on enterLobby() i got this following code:

this.userListRef.child(this.user.name).child('invite')
             .on('child_added', function(snapshot) {
           console.log("INVITE");
        });

And the code inside enterLobby() is executed every time. I'm missing something or the callback for .remove() doesn't work as supposed? Thank you

Upvotes: 0

Views: 266

Answers (1)

Anant
Anant

Reputation: 7428

The .on('child_added') handler will make sure the provided callback is called every time a child is added. This is why you are seeing the code execute multiple times. You may want to use .once('value') instead:

this.userListRef.child(this.user.name).child('invite').
  once('value', function(snapshot) { console.log("INVITE"); });

Upvotes: 1

Related Questions