vuejs/vue-rx

RxJS "pipeable" operators support

paulpdaniels opened this issue · 5 comments

RxJS now supports "pipeable" operators, it might make sense to support passing in the operator references through the Rx object bag during initialization, and then fallback to looking on the prototype. That might also make it easier to support other Observable implementations by letting the library users pass in adapter functions for their particular flavor of Observable. Areas like here

// rxjs v6.0.0
import { of } from 'rxjs';
import { filter, map, reduce } from 'rxjs/operators';

of(2, 'foo', 5, 'bar', 10)
  .pipe(  // pipeable is here
    filter(value => !isNaN(value)),
    map(value => value * 2),
    reduce((acc, value) => acc + value, 0)
  )
  .subscribe(value => console.log(value));
  // 34

This doesn't look like full RXJS 6.0 support yet. Could you document how to use vue-rx with RXJS 6 without the rxjs-compat layer?

https://docs.google.com/document/d/12nlLt71VLKb-z3YaSGzUfx6mJbc34nsMXtByPUN35cg/edit

Well it doesn't look like that many operators are actually used. So maybe it would be easier than I thought.

My thought was that instead of using the global Rx instead pass around a _RxLike, then support packages that define an adapter for the particular library (this is off the top of my head, if we agree to this approach I'll do some more due diligence on the exact syntax and required operators):

// For RxJS 6
import {share} from 'rxjs/operators/share'

const adapter = {
  create: observer => new Observable(observer),
  share
};

// For RxJS 5
import {Observable} from 'rxjs/Observable'
import 'rxjs/add/operator/share'

const adapter = {
  create: Observable.create,
  share: source => source.share()
};

// In createObservableMethod
// operator creation is hidden behind the adapter.
const {create, share} = adapter;
return share(create(creator));

We could also add development flags to run a check on the provided object bag to make sure that necessary features are included.