3.0.0 • Published 5 years ago

pri-plugin-rematch v3.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

pri-plugin-rematch · npm version

rematch is a nice framework for redux.

We provide pri-plugin-rematch to use it more easy!

Usage

npm i pri-plugin-rematch
.
├── src
│    └── models
│          ├── application.ts      # model file
│          └── user.ts             # model file
└── priconfig.json

Let’s try it! For example, create a model named user:

src/models/user.ts

import { model } from 'pri/model';

export default model({
  state: {
    name: 'jeck',
    age: 25
  },
  reducers: {
    increment: (state, count = 1) => {
      return {
        ...state,
        age: state.age + count
      };
    }
  },
  effects: {
    async asyncIncrement() {
      await new Promise(resolve => {
        setTimeout(resolve, 1000);
      });
      this.increment(5);
    }
  }
});

Then, use it in pages!

src/pages/index.tsx

import { connect } from 'pri/models';

@connect(
  state => {
    return {
      age: state.user.age
    };
  },
  dispatch => {
    return { increment: dispatch.user.increment, asyncIncrement: dispatch.user.asyncIncrement };
  }
)
export default class Page extends React.PureComponent<Props, State> {
  /**/
}

Import connect from 'pri/models' is a better way, 'pri/models' provides a strong typed connect function:

3.0.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago