Skip to content

Latest commit

 

History

History
26 lines (20 loc) · 859 Bytes

README.md

File metadata and controls

26 lines (20 loc) · 859 Bytes

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