简体   繁体   English

取消订阅 Firestore 文档快照侦听器

[英]Unsubscribe to a firestore document snapshot listener

Is there a way to unsubscribe to snapshot updates for a listener I have put on a Firestore document?有没有办法为我放在 Firestore 文档上的侦听器取消订阅快照更新? The documentation about this only shows how to unsubscribe to snapshot updates on a collection .有关此的文档仅显示如何取消订阅collection上的快照更新。 It says an unsubscribe function is sent back when the snapshot listener is set.它说unsubscribe function 在设置快照侦听器时被发回。 However, it does not look thats the case for snapshot listeners on a document.但是,文档上的快照侦听器看起来并非如此。 I dont get any unsubscribe function back, I only get an object that looks like this:我没有收到任何退订 function 回复,我只得到一个 object ,如下所示:

在此处输入图像描述

If it counts for anything, I am using the firebase emulator如果它很重要,我正在使用 firebase 仿真器

The onSnapshot method returns a function that, when called, will unsubscribe: onSnapshot方法返回一个 function ,调用时将取消订阅:

const unsubscribe = firebase.firestore().doc('path/to/some/doc').onSnapshot(...);

// later
unsubscribe();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM