Skip to content

Commit b1e748a

Browse files
author
wangyi
committed
## v4.6.0 2022-07-05
* [bug] fix the problem about the code updating, when using react-refresh babel and webpack plugins.
1 parent 2b2432c commit b1e748a

File tree

14 files changed

+198
-129
lines changed

14 files changed

+198
-129
lines changed

docs/changes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,6 @@
102102

103103
* [revert] rollback to 4.3.1
104104

105+
## v4.6.0 2022-07-05
106+
107+
* [bug] fix the problem about the code updating, when using react-refresh babel and webpack plugins.

docs/zh/changes.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,8 @@
100100

101101
## v4.5.4 2022-05-25
102102

103-
* [revert] 回滚至 4.3.1
103+
* [revert] 回滚至 4.3.1
104+
105+
## v4.6.0 2022-07-05
106+
107+
* [bug] 解决 react-refresh 插件热更新时,代码不能及时更新的问题。

example/package.json

Lines changed: 62 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,85 @@
44
"description": "this is a simple app for how to use useAgent",
55
"scripts": {
66
"tsc": "tsc",
7-
"start": "webpack-dev-server --config ./webpack.config.js --env.mode=development",
8-
"mock": "webpack-dev-server --config ./webpack.config.js --env.mock --env.mode=development",
7+
"start": "webpack serve --config ./webpack.config.js",
98
"build": "webpack --config ./webpack.config.js --env.mode=production",
109
"analyze": "webpack --config ./webpack.config.js --env.mode=analyze"
1110
},
1211
"dependencies": {
1312
"@types/classnames": "^2.2.7",
1413
"@types/react": "16.14.21",
1514
"@types/react-dom": "16.9.14",
16-
"agent-reducer": "4.5.3",
15+
"agent-reducer": "^4.6.0",
1716
"antd": "^4.16.13",
1817
"babel-polyfill": "^6.26.0",
1918
"classnames": "^2.2.6",
2019
"moment": "^2.24.0",
2120
"react": "^16.8.6",
2221
"react-dom": "^16.8.6",
23-
"use-agent-reducer": "4.5.1"
22+
"use-agent-reducer": "^4.6.0-beta.0"
2423
},
2524
"devDependencies": {
26-
"@babel/core": "7.15.8",
27-
"@babel/plugin-proposal-async-generator-functions": "7.15.8",
28-
"@babel/plugin-proposal-class-properties": "7.14.5",
29-
"@babel/plugin-proposal-decorators": "7.15.8",
30-
"@babel/plugin-proposal-export-default-from": "7.14.5",
31-
"@babel/plugin-proposal-export-namespace-from": "7.14.5",
32-
"@babel/plugin-transform-runtime": "7.15.8",
33-
"@babel/preset-env": "^7.15.8",
34-
"@babel/preset-react": "^7.14.5",
35-
"@babel/preset-typescript": "^7.15.0",
36-
"@babel/runtime": "7.15.4",
37-
"babel-eslint": "^9.0.0",
38-
"babel-loader": "^8.0.6",
25+
"@babel/core": "^7.14.3",
26+
"@babel/plugin-proposal-class-properties": "7.13.0",
27+
"@babel/plugin-proposal-decorators": "7.13.5",
28+
"@babel/plugin-transform-runtime": "7.13.10",
29+
"@babel/preset-env": "7.13.12",
30+
"@babel/preset-react": "7.13.13",
31+
"@babel/preset-typescript": "7.13.0",
32+
"@babel/runtime": "7.14.0",
33+
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
34+
"@types/jest": "^26.0.0",
35+
"@types/react-test-renderer": "^16.0.3",
36+
"@types/rewire": "2.5.28",
37+
"@typescript-eslint/eslint-plugin": "^4.21.0",
38+
"@typescript-eslint/parser": "4.21.0",
39+
"babel-jest": "26.0.1",
40+
"babel-loader": "^8.2.2",
3941
"babel-plugin-import": "^1.12.0",
4042
"babel-plugin-transform-react-remove-prop-types": "0.4.21",
41-
"css-loader": "^3.0.0",
42-
"eslint": "^8.2.0",
43-
"file-loader": "^4.0.0",
44-
"html-webpack-plugin": "^3.2.0",
45-
"husky": "^0.14.3",
46-
"less": "^3.9.0",
47-
"less-loader": "^5.0.0",
48-
"lint-staged": "^12.0.2",
49-
"react-test-renderer": "^16.7.0",
50-
"style-loader": "^0.23.1",
51-
"ts-loader": "^6.0.4",
52-
"tsconfig-paths-webpack-plugin": "^3.2.0",
53-
"tslint": "^5.12.0",
54-
"tslint-eslint-rules": "^5.4.0",
55-
"tslint-react": "^3.6.0",
56-
"typescript": "^3.8.3",
57-
"uglifyjs-webpack-plugin": "^1.1.2",
58-
"url-loader": "^2.0.1",
59-
"webpack": "^4.35.3",
60-
"webpack-api-mocker": "^1.6.0",
61-
"webpack-cli": "^4.9.1",
62-
"webpack-dev-server": "^3.7.2"
43+
"clean-webpack-plugin": "^4.0.0",
44+
"cooky-cutter": "^1.5.4",
45+
"core-js": "3.12.1",
46+
"css-loader": "5.2.5",
47+
"eslint": "^7.30.0",
48+
"eslint-config-airbnb": "^18.2.1",
49+
"eslint-config-prettier": "^8.3.0",
50+
"eslint-import-resolver-typescript": "^2.4.0",
51+
"eslint-plugin-import": "^2.22.1",
52+
"eslint-plugin-jsx-a11y": "^6.4.1",
53+
"eslint-plugin-react": "^7.23.1",
54+
"eslint-plugin-react-hooks": "^4.2.0",
55+
"file-loader": "5.1.0",
56+
"generator-dc": "2.0.0",
57+
"html-webpack-plugin": "5.3.1",
58+
"husky": "^7.0.1",
59+
"identity-obj-proxy": "^3.0.0",
60+
"jest": "26.6.3",
61+
"less": "4.1.1",
62+
"less-loader": "6.2.0",
63+
"lodash-webpack-plugin": "^0.11.6",
64+
"patch-package": "^6.2.2",
65+
"postcss-loader": "^7.0.0",
66+
"pre-commit": "^1.2.2",
67+
"prettier": "2.3.2",
68+
"prettier-eslint": "^12.0.0",
69+
"prettier-eslint-cli": "^5.0.1",
70+
"progress-bar-webpack-plugin": "^2.1.0",
71+
"react-refresh": "^0.14.0",
72+
"react-test-renderer": "^16.14.0",
73+
"regenerator-runtime": "0.13.5",
74+
"rewire": "5.0.0",
75+
"style-loader": "1.3.0",
76+
"ts-jest": "^26.1.0",
77+
"ts-node": "^10.8.1",
78+
"tsconfig-paths-webpack-plugin": "3.5.1",
79+
"typescript": "4.5.5",
80+
"url-loader": "4.1.1",
81+
"webpack": "5.71.0",
82+
"webpack-bundle-analyzer": "4.4.2",
83+
"webpack-cli": "4.10.0",
84+
"webpack-dev-server": "3.11.2",
85+
"webpackbar": "^5.0.2"
6386
},
6487
"engines": {
6588
"node": ">=8.0.0"

example/src/Layout.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ export default memo(() => {
3030
<NewFeatures/>
3131
<Title>model provider</Title>
3232
<ModelProvider/>
33-
<Title>effect provider</Title>
34-
<Effect/>
3533
</div>
3634
</div>
3735
);
38-
});
36+
});

example/src/components/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const ContentInput = memo(({value, onChange}: { value: string|undefined,
2727
}, []);
2828

2929
return (
30-
<Input style={{width: 160, marginRight: 8}} value={value} onChange={handleChange}/>
30+
<Input style={{width: 160, marginRight: 8}} value={value||''} onChange={handleChange}/>
3131
);
3232
});
3333

example/src/modelProvider/index.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,17 @@ export default function ModelProvider() {
7373
const {
7474
state,
7575
search,
76+
changePage
7677
} = agent;
7778

78-
const {changePage: changePageLatest} = useMiddleWare(agent, MiddleWarePresets.takeLatest());
79-
8079
useEffect(() => {
8180
search();
8281
}, []);
8382

8483
// handle page change
8584
const handleChangePage = useCallback(async (currentPage: number, pageSize: number = 10) => {
8685
// feedback searchParams with model object `searchParamsModel`.
87-
await changePageLatest(currentPage, pageSize);
86+
await changePage(currentPage, pageSize);
8887
}, [state]);
8988

9089
const renderPriorLevel = useCallback((value: PriorLevel) => {
@@ -104,10 +103,10 @@ export default function ModelProvider() {
104103
current={state.currentPage}
105104
total={state.total}
106105
pageSize={state.pageSize}
107-
onChange={handleChangePage}
106+
onChange={changePage}
108107
/>
109108
</TodoListProvider>
110109
</PageContent>
111110
);
112111

113-
}
112+
}

example/src/modelProvider/model.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ export default class SimpleTodoList implements OriginAgent<State> {
4242

4343
private async fetchDataSource(searchParams: SearchParams, currentPage: number, pageSize: number): Promise<State> {
4444
const fetchParams = {...searchParams, currentPage, pageSize};
45-
const {content: dataSource, total} = await fetchTodoList(fetchParams);
45+
const {content: dataSource, total} = await fetchTodoListWithDelay(fetchParams,currentPage===2?2000:0);
4646
// Copy searchParams here
4747
return {searchParams:{...searchParams}, dataSource, currentPage, pageSize, total};
4848
}
4949

5050
// this method should works with a page navigation
51-
@middleWare(MiddleWarePresets.takePromiseResolve())
51+
@middleWare(MiddleWarePresets.takeLatest())
5252
async changePage(currentPage: number, pageSize: number = 10): Promise<State> {
5353
const {searchParams} = this.state;
5454
return this.fetchDataSource(searchParams, currentPage, pageSize);
@@ -61,4 +61,4 @@ export default class SimpleTodoList implements OriginAgent<State> {
6161
return this.fetchDataSource(param, 1, 10);
6262
}
6363

64-
}
64+
}

example/src/newFeatures/index.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {MiddleWarePresets, weakSharing} from "agent-reducer";
1414
// often be reset back, if there is no living `Agent` built on it.
1515
const searchParamsModel = weakSharing(() => SearchParamsModel);
1616

17-
const simpleTodoList = weakSharing(() => SimpleTodoList);
17+
const simpleTodoList = new SimpleTodoList();
1818

1919
const SearchParamComponent = memo(() => {
2020

@@ -27,16 +27,18 @@ const SearchParamComponent = memo(() => {
2727
// So, model sharing only works on 'Agents' base on a same model object.
2828
// API `useAgentMethods` can optimize our component,
2929
// it never leads its consumer (component) rerender.
30-
const {search} = useAgentMethods(simpleTodoList.current);
30+
const {search} = useAgentMethods(simpleTodoList);
3131

3232
// API `useAgentSelector` can optimize our component,
3333
// it only leads its consumer (component) rerender, when the extracted data changes.
34-
const searchParams = useAgentSelector(simpleTodoList.current, ({searchParams}) => searchParams);
34+
const searchParams = useAgentSelector(simpleTodoList, ({searchParams}) => searchParams);
3535

3636
useEffect(() => {
3737
feedback(searchParams);
3838
}, [searchParams]);
3939

40+
console.log('search...',state)
41+
4042
const handleSubmit = useCallback(async () => {
4143
// submit current searchParams with model object `simpleTodoList`
4244
search(state);
@@ -56,23 +58,22 @@ const SearchParamComponent = memo(() => {
5658
export default function NewFeatures() {
5759

5860
// `Agent` bases on model `simpleTodoList`
59-
const agent = useAgentReducer(simpleTodoList.current);
61+
const agent = useAgentReducer(simpleTodoList);
6062

6163
const {
6264
state,
6365
search,
66+
changePage
6467
} = agent;
6568

66-
const {changePage: changePageLatest} = useMiddleWare(agent, MiddleWarePresets.takeLatest());
67-
6869
useEffect(() => {
6970
search();
7071
}, []);
7172

7273
// handle page change
7374
const handleChangePage = useCallback(async (currentPage: number, pageSize: number = 10) => {
7475
// feedback searchParams with model object `searchParamsModel`.
75-
await changePageLatest(currentPage, pageSize);
76+
await changePage(currentPage, pageSize);
7677
}, [state]);
7778

7879
const renderPriorLevel = useCallback((value: PriorLevel) => {
@@ -91,9 +92,9 @@ export default function NewFeatures() {
9192
current={state.currentPage}
9293
total={state.total}
9394
pageSize={state.pageSize}
94-
onChange={handleChangePage}
95+
onChange={changePage}
9596
/>
9697
</PageContent>
9798
);
9899

99-
}
100+
}

example/src/newFeatures/model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default class SimpleTodoList implements OriginAgent<State> {
4242

4343
private async fetchDataSource(searchParams: SearchParams, currentPage: number, pageSize: number): Promise<State> {
4444
const fetchParams = {...searchParams, currentPage, pageSize};
45-
const {content: dataSource, total} = await fetchTodoList(fetchParams);
45+
const {content: dataSource, total} = await fetchTodoListWithDelay(fetchParams, currentPage === 2 ? 3000 : 0);
4646
// Copy searchParams here
4747
return {searchParams:{...searchParams}, dataSource, currentPage, pageSize, total};
4848
}
@@ -61,4 +61,4 @@ export default class SimpleTodoList implements OriginAgent<State> {
6161
return this.fetchDataSource(param, 1, 10);
6262
}
6363

64-
}
64+
}

example/src/takeLatest/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ export default function TakeLatest() {
9292
</PageContent>
9393
);
9494

95-
}
95+
}

0 commit comments

Comments
 (0)