提问者:小点点

多次执行相同的firebase绑定(。on()方法)


在应用程序(例如使用react native的iOS/Android)或网站中,重新启动firebase绑定有问题吗?

以下代码为例:

var starCountRef = firebase.database().ref('posts/' + postId + '/starCount');
starCountRef.on('value', function(snapshot) {
  updateStarCount(postElement, snapshot.val());
});

如果我碰巧多次启动绑定函数:

starCountRef.on('value', function(snapshot) {
  updateStarCount(postElement, snapshot.val());
});

它会抹掉上一个吗? 或者它堆叠在另一个上面,我从firebase收到更新,以防对象多次更改?

先向社区表示感谢


共1个答案

匿名用户

如果您在一个位置有两个侦听器,则数据在网络流量方面不会重复。 两个侦听器将共享来自数据库的相同传入快照。

相关问题