How to remove listener for DocumentSnapshot events (Google Cloud FireStore)

后端 未结 1 1577
小蘑菇
小蘑菇 2020-12-03 10:00

I\'m new in Google Cloud FireStore.

The Document object has a function call onSnapshot to attaches a listener for DocumentSnapshot events.

Is there a funct

相关标签:
1条回答
  • 2020-12-03 10:56

    In case of the web and node.js SDK, calling onSnapshot returns a function that you need to save in a variable and call when you want to remove the listener.

    var unsubscribe = db.collection("cities").onSnapshot(function (querySnaphot) {
      // do something with the data.
    });
    
    
    // Stop listening to changes
    unsubscribe();
    

    The other SDKs offer similar functionality.

    See https://firebase.google.com/docs/firestore/query-data/listen#detach_a_listener for reference.

    0 讨论(0)
提交回复
热议问题