javascript - firebase 查询在客户端返回部分更新的节点
问题描述
由于某些原因,我遇到了无法重现的错误
每次收到添加/更新/删除的数据时,我都会根据当前时间戳触发一个新的 Firebase 查询
一个节点有这个模式
$UID:
color:
description:
infos:
temperature :
low:
high:
timestamp:
title:
update:
因此,在我的应用程序中,我用鼠标移动了一个图形对象并将值更新为 db,如下所示:
this.editor.updates[`${this.uid}/update`] = true;
this.editor.updates[`${this.uid}/add`] = null;
this.editor.updates[`${this.uid}/infos`] = "my new infos";
this.editor.updates[`${this.uid}/timestamp`] = Date.now();
// then I send `this.editor.updates` object to the realtime database
我正在使用的侦听器是snapshotChanges
如此立即检索 eventType 的对象child_added
这可能是正常的,因为这是向侦听器发出的第一个值,但唯一的问题是我得到了一个仅包含更新的属性的部分对象infos
,timestamp
并且该对象还update
应该包含temperature
,color
和.title
description
看起来问题可能来自这样一个事实,即我立即在订阅中触发了一个新查询,这导致了奇怪的行为。这是我的递归查询
在我的主要组件的 ngOnInit 里面
public date$ = new BehaviorSubject(null);
...
this.date$.pipe(
switchMap(
(date) => {
this.currQuery = this.db.getActionsStartAtNow('path', date)
return (this.currQuery);
}
)
).subscribe(
(actionsList:any[]) => {
//process the data
//then trigger updated query
this.date$.next(Date.now())
}
)
在我的数据库服务中
import { AngularFireDatabase } from '@angular/fire/database';
import { Observable } from 'rxjs';
import 'rxjs/add/observable/empty';
constructor(private db:AngularFireDatabase) {
}
...
getActionsStartAtNow(path:string, date?:number){
return (date ? this.db.list(path, (ref) => {
return (ref.orderByChild('timestamp').startAt(date))
}
).snapshotChanges() : Observable.empty()
)
}
错误的日志
对象{信息:“0-1602194400000-1602626400000-0-0-1-0”,时间戳:1605429748370,更新:真}
正确的日志
对象{颜色:3,描述:“”,信息:“0-1602194400000-1602626400000-0-0-1-0”,温度:{…},时间戳:1605429748370,标题:“”,更新:真}
解决方案
推荐阅读
- primefaces - PRIMEFACES:PRIMEFACES 中的 XHTML 文件中可以运行哪些 java 代码
- javascript - Javascript过滤数组内的数据数组
- c++ - 项目链接和编译文件
- javascript - 如何增加localStorage长度
- r - 在过滤后的闪亮散点图中保留现有选择
- javascript - Repl.it 未处理的承诺拒绝
- amazon-web-services - 使用 ECS 更改 Docker CLI 上下文的 AWS 区域
- powershell - System.Windows.Forms.Timer 滴答间隔短于定义的间隔
- javascript - 自动完成:仅允许从建议列表中选择值
- mysql - MySQL存储过程执行需要很长时间