【问题标题】:Firebase event guarantee child added child removedFirebase 事件保证子添加子删除
【发布时间】:2016-10-14 17:40:03
【问题描述】:

Firebase documentation 引号之一上:

每当修改子节点时都会触发child_changed 事件。这包括对子节点后代的任何修改。它通常与child_addedchild_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_addedchild_removed 之间有一点延迟,以至于在注册child_removed 侦听器之前有一个子移除事件,那么child_removed 侦听器是否能够捕获该子移除事件?

编辑

听众应该根据答案和firebase doc的另一个引用来工作:

事件最终将始终反映数据的正确状态,即使在本地操作或时间导致暂时性差异的情况下,例如暂时失去网络连接。

【问题讨论】:

    标签: javascript firebase firebase-realtime-database


    【解决方案1】:

    事件几乎同时注册。这取决于您对远程主机的延迟有多快,但它不应干扰您的意图。

    【讨论】:

      猜你喜欢
      • 2011-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-28
      • 1970-01-01
      • 2019-04-16
      • 1970-01-01
      • 2018-05-05
      相关资源
      最近更新 更多