feathersjs-ecosystem / feathers-reactive

Reactive API extensions for Feathers services
MIT License
216 stars 37 forks source link

Add support for params and query object streams #50

Open daffl opened 7 years ago

daffl commented 7 years ago

Basically, if one of the arguments (or the params.query) is an observable we should do what was suggested in https://github.com/feathersjs/feathers-reactive/issues/39 and mergeMap them into a single stream:

const service = app.service('messages');
const query = new RxJS.BehaviorSubject({ $skip: 0 });

const find = query.mergeMap(query => service.find({ query }));

find.subscribe(data => console.log('Data is', data));

query.next({ $skip: 10 });
j2L4e commented 7 years ago

You also need to choose if you want to switch or merge. e.g. classic pagination vs infinite scrolling. How about this:

find(params$, merge = false){
  if(isObservable(params$)){
    return merge 
      ? params$.mergeMap(params => this.find(params)) 
      : params$.switchMap(params => this.find(params));
  } else {
    return this._find(params$); // "normal" find
  }
}

Edit: I think switching should be the default behavior.