id | title |
---|---|
qna |
常见问题 |
tsconfig.json
里面设置了:
{
"compilerOptions": {
"strict": true,
// 或
"noImplicitThis": true,
}
}
更推荐使用方法一,可以获得完善的 TS 类型提示
方法一:使用 createModel
工具方法来包裹你的 model 对象
+ import { createModel } from '@ice/store';
- const counter = {
+ const counter = createModel({
state: 0,
reducers: {
increment: (prevState) => prevState + 1,
decrement: (prevState) => prevState - 1,
},
effects: () => ({
async asyncDecrement() {
await delay(1000);
this.decrement();
},
}),
- };
+ });
方法二:使用 dispatch
const counter = {
state: 0,
reducers: {
increment: (prevState) => prevState + 1,
decrement: (prevState) => prevState - 1,
},
- effects: () => ({
+ effects: (dispatch) => ({
async asyncDecrement() {
await delay(1000);
- // this.decrement();
+ dispatch.counter.decrement();
},
}),
};