javascript - Firebase Firestore : when do promises from offline write operations resolve?

标签 javascript firebase google-cloud-firestore offline

我按照文档中的说明离线激活:

firebase
    .firestore()
    .enablePersistence()
    .then(() => {
      console.log('offlinemode acctivated')
    })

日志如我所料出现。

像这样添加数据时:

db
    .collection('foo')
    .add({foo: 'bar'})
    .then(docRef => {
      console.log('Added Foo: ', docRef.id)
      // do some stuff here with the newly created foo and it's id.
    })
    .catch(console.error)

.then().catch() 都不会在离线时被调用。即使在执行此回调时对象已添加到我的离线数据库中的 foo 集合中也是如此:

db
    .collection('foo')
    .onSnapshot(callback)

我错过了什么吗?我希望 promise 要么失败要么解决,因此我可以做出相应的 react 。

最佳答案

只有当服务器确认写入已完成时,Firestore 中写入操作的 promise 才会解决,即使它们可能已成功写入本地缓存。

关于javascript - Firebase Firestore : when do promises from offline write operations resolve?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49818095/

相关文章:

javascript - 动态 json 回调函数仅检索最后一个值

java - Firebase 并发锁定/解锁写访问多个设备

ios - 如何在 swift 4.0 中获取 firebase-realtime-database 中的特定值

firebase - 如何在 Flutter 中正确调用 FirebaseFirestore.instance.clearPersistence()?

firebase - 似乎无法获取包含子集合的文档

google-app-engine - 使用 App Engine 的本地或开发 Google Cloud Firestore 数据库

javascript - 使用 PHP 和 JavaScript 从心跳列表构建正常运行时间图

javascript - 函数构造函数浏览器支持

javascript - 如何在 Node js 中启用 `ignoreUndefinedProperties`

javascript - 以模态打开pdf文件可能吗?