随时不要重新加载Firestore

时间:2018-08-11 19:51:31

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

我实际上是在一个应用程序上独自工作,文档编写有些困难。

这是我的问题:我有此代码

/**
 * @param postId
 * @param query
 */
public getCommentToPost(postId: string): Observable<CommentModel[]> {
  return this.afStore.collection('posts')
    .doc(postId).collection<CommentModel>('comments').valueChanges();
}

afStore是对AngularFirestore的引用; (我正在使用angularfire2)。

问题是,每次在最终集合(此处为comments)中进行修改时,仅会重新加载所有输出。

它仍然非常快,但是我有时会在其他未修改的评论上看到小的加载微调器。

是否可以仅加载新评论?

1 个答案:

答案 0 :(得分:2)

对于Firestore中集合/查询的任何更新,您将获得受影响的文档 以及对该文档进行的更改的类型,即添加,更改或删除的文档。在AngularFire2中,该信息被映射到DocumentChangeAction。但是valueChanges没有得到DocumentChangeAction,因此那里没有有关更改类型的信息。使用其他流式传输方法之一(即snapshotChanges)来了解进行了哪种类型的更改。

相关问题