如何检查订阅是否已完成加载所有现有行?

Bas*_*sit 6 observable rxjs firebase firebase-realtime-database angularfire2

我想在启动时加载所有项目而不显示任何消息,但是一旦加载后.我想捕获订阅者中的任何新行并将其显示给桌面通知.

问题是,我不知道如何检查是否所有以前的项目都已加载,以及该行是新项目还是来自之前的现有项目.

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
});
Run Code Online (Sandbox Code Playgroud)

bas*_*ash 0

我有用户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");
});
Run Code Online (Sandbox Code Playgroud)