angular - Angularfire:valuechanges observable 发出两次
问题描述
语境 :
我正在与 Angularfire 6.1.5 和 firebase 8.6.1 聊天
我的 Firestore 包含一个集合“讨论”。每个讨论都包含一个子集合“消息”。
我的问题是关于新消息的处理程序部分。我需要接收某人创建的最后一条新消息并显示它。
代码 :
我正在用这个 observable 处理新消息:
return this.db.collection<Message>(`discussions/${id}/messages`, ref => ref.orderBy('createdAt').limitToLast(1))
.valueChanges({ idField: '_id' })
.pipe(...);
添加消息的方法:
sendMessage(discussionId: Discussion['_id'], message: Message): void {
this.db.collection<Message>(`discussions/${discussionId}/messages`).add(message);
}
问题 :
当我只添加一条消息时,valueChanges()
会发出两次。我只有一个订阅者。
这种双重发射是设计使然还是错误?
谢谢 :)
解决方案
推荐阅读
- node.js - 使用 NODE 和 Express 创建后发送 html 文件
- amazon-web-services - 从 lmabda 以有限的访问权限在 ec2 中运行 php 文件
- google-apps-script - 工作表上的 Google 脚本 - onEdit 脚本将已编辑的单元格合并到其前面的列
- python - 回归网络:哪个损失函数?
- c# - 在 C# WinForm 项目中移动图片框时如何绘制轨迹
- awk - 如何将更改应用到 AIX 中许多文件的某些行?
- javascript - 使用 axios 将数据发送到输入 ReactJS 中的每个更改
- sql - 如何在 Big Query 的表中计算具有条件的元素
- c# - 当您从另一个 sup 类的子类调用方法时,如何从超类的子类执行方法?
- c# - 部署时的 HttpClient 性能问题