Skip to content

Use same interfaces found in Redux and Redux-Observable to manager app state via new React Context Api

Notifications You must be signed in to change notification settings

skoch-tf/context-observable

 
 

Repository files navigation

Context-Observable

Travis npm package Coveralls

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

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 manager the state of your app?

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

What you need to avoid "side-effect"?

Context-Observable following 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>

About

Use same interfaces found in Redux and Redux-Observable to manager app state via new React Context Api

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%