我想在开始时加载所有项目而不显示任何消息,但在加载后加载一次。我想捕获订阅者中的任何新行并将其显示到桌面通知。
问题是,我不确定如何检查是否所有以前的项目都已加载,以及该行是新项目还是来自以前的现有项目。
this.items = this.af.database.list('notifications/'+this.uid+'/');
this.items.subscribe(list => {
list.forEach(row => {
// doing something here...
});
// once all the rows are finished loading, then any new row, show desktop notification message
});
最佳答案
我有用户 lodash 对于最少的代码。
// this varible holds the initial loaded keys
let loadedKeys = [];
this.items = this.af.database.list('notifications/'+this.uid+'/');
this.items.subscribe((list)=>{
// we skip it while initial load
if(!_.isEmpty(loadedKeys)){
// different is the new keys
let newKeys = _.difference(_.map(list, "$key"), loadedKeys);
if(!_.isEmpty(newKeys)){
// ... notification code here
}
}
loadedKeys = _.map(list, "$key");
});
关于firebase - 如何检查订阅是否完成加载所有现有行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39812877/