New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support RxJS 6 #6

Open
teramotodaiki opened this Issue Jul 19, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@teramotodaiki
Copy link

teramotodaiki commented Jul 19, 2018

Thank you for useful module :)

This is a proposal (not PR).
In rxjs version 6, it is recommended to use pipe instead of prototype.
https://github.com/ReactiveX/rxjs/blob/91088dae1df097be2370c73300ffa11b27fd0100/doc/pipeable-operators.md

Here is a pipeable operator of ofAction.

import { ActionsObservable } from 'redux-observable';
import { Action, ActionCreator } from 'typescript-fsa';
import { filter } from 'rxjs/operators';
import { MonoTypeOperatorFunction } from 'rxjs';

export function ofAction<P>(
  actionCreator: ActionCreator<P>
): MonoTypeOperatorFunction<Action<P>> {
  return function(actions$) {
    return actions$.pipe(filter(actionCreator.match)) as ActionsObservable<
      Action<P>
    >;
  };
}

e.g.

import { ofAction } from 'typescript-fsa-redux-observable';

action$.pipe(
    ofAction(actions.someActionCreator),
    map(action => actions.otherActionCreator)
);

I think this is not the best answer, but it works.
Thanks!

@jollytoad

This comment has been minimized.

Copy link

jollytoad commented Aug 27, 2018

Thanks @teramotodaiki, I've just updated to Typescript 3.0 & redux-observable 1.0.0 & RxJS 6.x ... your suggestion was very helpful in migration. I've refined the ofAction a little further if you are interested.

This also make use of the new unknown type in TS 3, which is very useful in modelling Actions with an unknown payload, narrowing from an Action<unknown> to Action<P>...

export const ofAction = <P>(actionCreator: ActionCreator<P>): OperatorFunction<Action<unknown>, Action<P>> =>
    (actions$): Observable<Action<P>> =>
        actions$.pipe(filter(actionCreator.match))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment