【问题标题】:RxJS combineLatest not emitting properly after updating observableRxJS combineLatest 在更新 observable 后没有正确发射
【发布时间】:2019-05-05 11:36:41
【问题描述】:

我有以下 RxJS combineLatest 等到三个对象从我的 Firebase Firestore(用户、艺术家、发布)返回,我将这些对象合并并展平为一组对象:

combineLatest([this.release$, this.artist$, this.auth.user$]).subscribe(
  (results) => {
    console.log(results)
    this.releasePage = true;
    var releaseArray = this.helper.flattenArray(results);
    console.log(releaseArray);
  }
)

当我加载此页面并 console.log 时,releaseArray(具有扁平对象数组)我可以按预期看到所有 3 个对象。

现在问题出现了。用户可以编辑release 信息,但是当用户保存更新时,我收到有关未定义发布对象中的属性的错误。当我查看发布数组的日志时,只有艺术家和用户对象在新的releaseArray 中返回。为什么这个对象数组中没有返回释放对象?

这是一张图片,前两个日志语句在页面加载时显示,最后两个日志语句在 Firestore 更新数据后显示,因此在值更改后发出:

当我进入 Firestore 并直接更新对象的属性时,observable 会返回 3 个更新的对象。

值得一提的是我用于更新对象的 Firestore AngularFire2 更新代码:

this.db.updateAt(`submissions/${this.submission.id}`, {
        ...form.value
})

我的数据库服务中的updateAt 方法:

  updateAt(path: string, data: Object): Promise<any> {
    const segments = path.split('/').filter(v => v);
    if (segments.length % 2) {
      // Odd is always a collection
      return this.afs.collection(path).add(data);
    } else {
      // Even is always document
      return this.afs.doc(path).set(data, { merge: true });
    }
  }

让我知道您还需要什么来帮助解决这个问题,谢谢!

【问题讨论】:

    标签: angular firebase rxjs google-cloud-firestore angularfire2


    【解决方案1】:

    只是我太笨了,当我提交带有更新的页面时,发布 id 以及更新的内容都在更新,所以 observable 无法找到它最初被要求观察的内容......

    我补充说:

    if(!this.submitForm.value.submissionUID) {
      this.submitForm.value.submissionUID = Math.random().toString(36).substring(2);
    }
    

    如果提交UID已经存在,这会重新更新它......

    【讨论】:

      猜你喜欢
      • 2021-02-21
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-29
      • 2022-01-24
      相关资源
      最近更新 更多