Unlink listener for parent does it applied to children in Firebase

后端 未结 3 1961
隐瞒了意图╮
隐瞒了意图╮ 2020-12-19 12:08

I am using firebase to synch data in a real time app. After some treatment, I want to unlink all listeners added. So I put

myRef.off();

But

3条回答
  •  被撕碎了的回忆
    2020-12-19 12:33

    Thanks to the posts in this thread, I was able to figure out how stop my callbacks which kept firing after their initial invocation for the intended Firebase calls they were passed to. This unexpected callback was even happening when I updated directly in the console.

    I got the following solution to disengage listeners once the callback runs:

    var queryRef = someItemRef.limitToLast(1);
    
    queryRef.on('child_added', function (data) {
    
        queryRef.off();
        onAddSomeItemReadyFunc(data);
    });
    

    For me - understanding the listener logic and avoiding "rogue callbacks" - has been a trickier aspect of working with Firebase DB. But we're gettn' there :)

    @Frank van Puffelen, thank you yet again for good notes and examples to help us Firebase-client devs get back on track!

提交回复
热议问题