Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138337

How to detach Firestore listener?

$
0
0

I'm making a web game with Firestore. I use the Firestore listener and want to detach it.

The official document shows this code:

var unsubscribe = db.collection("cities")
    .onSnapshot(function (){
      // Respond to data
      // ...
    });

// Later ...

// Stop listening to changes
unsubscribe();

But in this way, when detaching listener, nameless function works again. So I can't do this.

var name = "New York"
var unsubscribe = db.collection("cities")
    .onSnapshot(function (doc){
      var data = doc.data();
      if(data.name == name){
        // Stop listening to changes
        unsubscribe()
      }
    });

If I do this, infinite loop occurs because unsubscribe() calls unsubscribe(). How can I detach listener without unsubscribe() working?


Viewing all articles
Browse latest Browse all 138337

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>