feathers-reactive icon indicating copy to clipboard operation
feathers-reactive copied to clipboard

Add support for params and query object streams

Open daffl opened this issue 8 years ago • 1 comments

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 });

daffl avatar Apr 12 '17 00:04 daffl

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.

j2L4e avatar May 08 '17 08:05 j2L4e