IhorSyerkov / connect-rxjs-to-react

Connect rxjs to React component in Redux style... but without dispatch and constants.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

connect-rxjs-to-react

Simple way to connect rxjs to React component in Redux style... but without dispatch and constants.

// CounterActions.js
const counterActions = createActions(["increment", "decrement", "reset"])

// CounterReducer.js
const CounterReducer$ = Rx.Observable.of(() => initialState)
  .merge(
    counterActions.increment.map(payload => state => state + payload),
    counterActions.decrement.map(payload => state => state - payload),
    counterActions.reset.map(_payload => _state => initialState),
  );

// Counter.jsx
const Counter = ({ counter, increment, decrement, reset }) => (
  ...
);

connect(({ counter }) => ({ counter }), counterActions)(Counter);

Read more about RxJS with React: http://michalzalecki.com/use-rxjs-with-react

About

Connect rxjs to React component in Redux style... but without dispatch and constants.


Languages

Language:JavaScript 99.1%Language:HTML 0.9%