【发布时间】:2016-10-14 17:40:03
【问题描述】:
在Firebase documentation 引号之一上:
每当修改子节点时都会触发
child_changed事件。这包括对子节点后代的任何修改。它通常与child_added和child_removed结合使用,以响应对项目列表的更改。
现在说我有这个结构:
parent-node: {
child1,
child2,
...
}
我按以下顺序将侦听器附加到父节点:
parentRef.on('child_added', function() {
// Record the children to my memory cache
}
parentRef.on('child_removed', function() {
// Remove the deleted children from my memory cache
}
parentRef.on('child_changed', function() {
// Do something with the children in my memory cache
}
如果像上面这样注册监听器,是否意味着我不会错过对孩子的任何更改?
Firebase 是否同时注册了侦听器?或者说如果在注册child_added 和child_removed 之间有一点延迟,以至于在注册child_removed 侦听器之前有一个子移除事件,那么child_removed 侦听器是否能够捕获该子移除事件?
编辑
听众应该根据答案和firebase doc的另一个引用来工作:
事件最终将始终反映数据的正确状态,即使在本地操作或时间导致暂时性差异的情况下,例如暂时失去网络连接。
【问题讨论】:
标签: javascript firebase firebase-realtime-database