Skip to content

Commit b02ce48

Browse files
committed
typehints
1 parent 9a062fd commit b02ce48

File tree

3 files changed

+27
-31
lines changed

3 files changed

+27
-31
lines changed

umi/config/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// ref: https://umijs.org/config/
22
export default {
3+
title: 'todos',
34
antd: {},
45
dva: { hmr: true },
56
dynamicImport: {},

umi/package.json

+18-18
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@
88
"precommit": "lint-staged"
99
},
1010
"dependencies": {
11-
"ahooks": "^2.10.0",
12-
"antd": "^4.15.1",
13-
"axios": "^0.21.1",
11+
"ahooks": "^2.10.12",
12+
"antd": "^4.16.13",
13+
"axios": "^0.24.0",
1414
"react": "^17.0.2",
1515
"react-dom": "^17.0.2"
1616
},
1717
"devDependencies": {
18-
"@ant-design/icons": "^4.6.2",
19-
"@types/node": "^14.14.41",
20-
"@types/react": "17.0.3",
21-
"@typescript-eslint/eslint-plugin": "^4.22.0",
18+
"@ant-design/icons": "^4.7.0",
19+
"@types/node": "^16.11.7",
20+
"@types/react": "17.0.35",
21+
"@typescript-eslint/eslint-plugin": "^5.4.0",
2222
"@umijs/plugin-blocks": "^2.2.2",
2323
"@umijs/plugin-sass": "^1.1.1",
24-
"@umijs/preset-react": "^1.8.4",
24+
"@umijs/preset-react": "^1.8.29",
2525
"@umijs/preset-ui": "^2.2.9",
2626
"babel-eslint": "^10.1.0",
27-
"eslint": "^7.24.0",
27+
"eslint": "^8.2.0",
2828
"eslint-config-umi": "^1.6.0",
29-
"eslint-plugin-flowtype": "^5.7.0",
30-
"eslint-plugin-import": "^2.22.1",
31-
"eslint-plugin-jsx-a11y": "^6.4.1",
32-
"eslint-plugin-react": "^7.23.2",
33-
"eslint-plugin-react-hooks": "^4.2.0",
34-
"husky": "^6.0.0",
35-
"lint-staged": "^10.5.4",
29+
"eslint-plugin-flowtype": "^8.0.3",
30+
"eslint-plugin-import": "^2.25.3",
31+
"eslint-plugin-jsx-a11y": "^6.5.1",
32+
"eslint-plugin-react": "^7.27.0",
33+
"eslint-plugin-react-hooks": "^4.3.0",
34+
"husky": "^7.0.4",
35+
"lint-staged": "^12.0.2",
3636
"react-test-renderer": "^17.0.2",
37-
"typescript": "^4.2.4",
38-
"umi": "3.4.8"
37+
"typescript": "^4.5.2",
38+
"umi": "3.5.20"
3939
},
4040
"lint-staged": {},
4141
"engines": {

umi/src/pages/todos/model.ts

+8-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// 更新model层中state –>
99
// 触发view层的render方法进行重新渲染 –>
1010
// 页面更新
11-
import { Effect, Reducer } from 'umi';
11+
import { Effect, ImmerReducer } from 'umi';
1212
import { getRemoteItems, getUser } from '@/services/remoteItems';
1313
import { delay } from '@/utils';
1414

@@ -26,8 +26,8 @@ interface TodosModelType {
2626
namespace: 'todos';
2727
state: TodosState;
2828
reducers: {
29-
addTodo: Reducer<TodosState>;
30-
delTodo: Reducer<TodosState>;
29+
addTodo: ImmerReducer<TodosState>;
30+
delTodo: ImmerReducer<TodosState>;
3131
};
3232
effects: {
3333
addTodoAsync: Effect;
@@ -36,11 +36,6 @@ interface TodosModelType {
3636
};
3737
}
3838

39-
interface TodosAction<T> {
40-
type: string;
41-
payload: T;
42-
}
43-
4439
const TodosModel: TodosModelType = {
4540
namespace: 'todos',
4641

@@ -53,7 +48,7 @@ const TodosModel: TodosModelType = {
5348

5449
// type Reducer<S, A> = (state: S, action: A) => S
5550
reducers: {
56-
addTodo(state: TodosState, action: TodosAction<{ memo: string }>) {
51+
addTodo(state, action) {
5752
let { id } = state;
5853
id++;
5954
const { memo } = action.payload;
@@ -66,18 +61,18 @@ const TodosModel: TodosModelType = {
6661
};
6762
},
6863

69-
delTodo(state: TodosState, action: TodosAction<{ id: number }>) {
64+
delTodo(state, action) {
7065
const { id } = action.payload;
7166
const items = { ...state.items };
7267
delete items[id];
7368
return { id: state.id, items };
7469
},
7570
}, // end reducers
7671

77-
// yield call 调用异步方法
78-
// put 调用同步方法, 必须触发Action
72+
// call 调用异步方法
73+
// put 触发Action
7974
effects: {
80-
*addTodoAsync({ payload }: TodosAction<{ id: number }>, { put }: any) {
75+
*addTodoAsync({ payload }, { put }) {
8176
yield delay(1000);
8277
yield put({
8378
type: 'addTodo',

0 commit comments

Comments
 (0)