context-observable

1.0.3 • Public • Published

Context-Observable

Travis npm package Coverage Status

Context-Observable Component manages the state of your React App using new React Context Api following same interfaces of Redux (actions and reducers) and using the same idea behind redux-observable to avoid "side-effect".

The Context-Observable Component

Look how it's simple

Dependencies

  • React v16.3 (https://reactjs.org/)
  • Rxjs 5 (http://reactivex.io/rxjs)

Install

Via npm

npm install --save context-observable

Via UMD (to use as jsbin, etc..)

https://raw.githubusercontent.com/stvkoch/context-observable/master/umd/context-observable.js

Run Demo

git clone git@github.com:stvkoch/context-observable.git
cd context-observable
npm start

What you need to manages the state of your app?

As a redux, you will need create reducers and actions.

What you need to avoid "side-effect"?

Context-Observable follow same ideia behind redux-observable, so what you will need is create your epics the same way that you already do in redux-observable.

How I setup Context-Observable?

Then you import Context-Observable Component and pass your epics and reducers.

import { ContextObservable } from "context-observable";

import rootEpics as epics from "./epics";
import rootReducers as reducer from "./reducers";

const App = () => (
  <ContextObservable {...{ epics, reducer }}>
    <Product />
  </ContextObservable>
);

How you dispatch actions to epics and to reducers?

import {Consumer} from 'context-observable';

  // ... in your render method:
  <Consumer>
    {({ state, dispatch }) => (
      <React.Fragment>
        <ul>
          {state &&
            state.products.map(p => (
              <li key={p.id}>
                <button onClick={() => dispatch(addProduct(p))}>
                  {p.name}
                </button>
              </li>
            ))}
        </ul>
      </React.Fragment>
    )}
  </Consumer>

Package Sidebar

Install

npm i context-observable

Weekly Downloads

3

Version

1.0.3

License

MIT

Unpacked Size

30.6 kB

Total Files

11

Last publish

Collaborators

  • stvkoch