0.6.0 • Published 6 years ago

rxloop v0.6.0

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

rxLoop

rxLoop = Redux + redux-observable.

Predictable state container for JavaScript apps based on RxJS, like Redux with redux-observable middleware.

  1. Using RxJS instead of Redux.
  2. Easy study, only four apis: app.model、app.dispatch、app.getState、app.stream.
  3. Cancel async actions easyly.

Installation

$ npm i rxloop

Hello rxloop

import { Observable } from 'rxjs';
import { mergeMap, map } from 'rxjs/operators';
import rxLoop from 'rxloop';

const counterModel = {
  name: 'counter',
  state: {
    counter: 0,
  },
  reducers: {
    increment(state) {
      return {
        ...state,
        counter: state.counter + 1
      };
    },
  },
  epics: {
    getData(action$) {
      return action$.pipe(
        mergeMap(() => {
          return Observable.fromPromise(
            // Promise
            api().catch((error) => {
              return { error };
            }),
          );
        }),
        map((data) => {
          return {
            type: 'increment',
          };
        }),
      );
    }
  }
};

const app = rxLoop();
app.model(counterModel);

app.stream('counter').subscribe((state) => {
  // this.setState(state);
});

// sync update
app.dispatch({
  type: 'counter/increment',
});

// async update
app.dispatch({
  type: 'counter/getData',
});

Documentation

rxloop

Examples

examples

Releases

releases

License

MIT

0.6.0

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago