0.10.0 • Published 1 year ago

resaga v0.10.0

Weekly downloads
24
License
MIT
Repository
github
Last release
1 year ago

React Resaga

npm version codecov Build Status

A reusable Reducer and Saga HOC library

Documentation

https://resaga.quandh.com

Install

npm install --save resaga

Basic Usages

Wrap your component by resaga HOC

// MyBookPage.js
export class MyBookPage extends PureComponent {
  // ...
}

const configs = {
  name: 'MyBookPage',
  requests: {
    getBooks: () => fetch('get', '/api/books'),
  },
};
export default resaga(configs)(MyBookPage);
  • configs.name: unique, work as an identification
  • requests.getBooks: tell resaga what to do when 'getBooks' is dispatched
  • resaga(configs)(MyBookPage) wrap MyBookPage by resaga HOC with your own configs

Use the injected props

Props resaga will be attached to MyBookPage component

// MyBookPage.js
componentDidMount = () => this.props.resaga.dispatch('getBooks');
componentWillReceiveProps = (nextProps) =>
  this.props.resaga.analyse(
    nextProps,
    { getBooks: { onSuccess: this.getBooksSuccess } }
  );
getBooksSuccess = (books) => {
  // will be called when server returns some results
}

Inject resaga reducer and sagas to your route

This is based on reactboilerplate routes.js file

const myBookPage = 'MyBookPage'; // should match `configs.page` that we set in the beginning
<Route
  path={'/books'}
  name={'My Book Page'}
  getComponent={(nextState, cb) => {
    const importModules = Promise.all([
      import('resaga'),
      import('containers/MyBookPage'),
    ]);

    const renderRoute = loadModule(cb);
    
    importModules.then(([resaga, component]) => {
      const reducer = resaga.reducer(myBookPage);
      injectReducer(myBookPage, reducer);
      injectSagas(resaga.sagas);
      renderRoute(component);
    });

    importModules.catch(errorLoading);
  }}
/>

Tests!

Run them: npm run test:jest

Check coverage: npm run coverage

Scripts

Run with npm run <script>.

release

Takes the same argument as npm publish, i.e. [major|minor|patch|x.x.x], then tags a new version, publishes, and pushes the version commit and tag to origin/master. Usage: npm run release -- [major|minor|patch|x.x.x]. Remember to update the CHANGELOG before releasing!

build

Runs the build scripts detailed below.

build:component

Transpiles the source in lib/ and outputs it to build/, as well as creating a UMD bundle in dist/.

test

Runs the test scripts detailed below.

test:lint

Runs eslint on the source.

test:jest

Runs the unit tests with jest.

coverage

Runs the unit tests and creates a code coverage report.

0.10.0

1 year ago

0.9.6

4 years ago

0.9.4

4 years ago

0.9.5

4 years ago

0.9.0

5 years ago

0.8.1

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago