From 3abb02d53b8bbfa0ff6e965288a1701d49f4971f Mon Sep 17 00:00:00 2001 From: unadlib Date: Sat, 25 May 2024 16:44:09 +0800 Subject: [PATCH 1/6] chore(redux): upgrade redux and react-redux --- TODO.md | 10 +-- packages/reactant-last-action/package.json | 4 +- packages/reactant-module/package.json | 2 +- packages/reactant-redux/package.json | 4 +- packages/reactant-router/package.json | 8 +-- packages/reactant-storage/package.json | 8 +-- packages/reactant/package.json | 2 +- packages/reactant/src/hooks/useConnector.ts | 6 +- packages/reactant/src/interfaces.ts | 5 +- packages/reactant/test/useConnector.test.tsx | 65 ++++++++++++++++++-- yarn.lock | 54 ++++++++++------ 11 files changed, 119 insertions(+), 49 deletions(-) diff --git a/TODO.md b/TODO.md index 16befc3f7..df5d7a14e 100644 --- a/TODO.md +++ b/TODO.md @@ -1,14 +1,16 @@ # TODO - [x] update API docs - [x] use Mutative -- [ ] Implementing non-invasive injection for DI +- [ ] upgrade react/react-dom 17.x and 18.x +- [x] upgrade redux v5 +- [x] upgrade react-redux v8.1.3 for React 17.x and 18.x - [x] upgrade react-native +- [ ] add example with `bun` +- [ ] add example with `vite` +- [ ] Implementing non-invasive injection for DI - [ ] support TS 5.0 new decorator(https://github.com/tc39/proposal-decorators), [more detail](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#differences-with-experimental-legacy-decorators) - [ ] upgrade inversify v6 - [ ] upgrade react-router v6.22.1 -- [ ] upgrade react/react-dom 17.x and 18.x -- [ ] upgrade redux v5 -- [ ] upgrade react-redux v8.1.3 for React 17.x and 18.x - [ ] support `upgrade` CLI - [ ] dynamic unloading module - [ ] improve CLI about `bun` diff --git a/packages/reactant-last-action/package.json b/packages/reactant-last-action/package.json index 41e3688f5..72e018020 100644 --- a/packages/reactant-last-action/package.json +++ b/packages/reactant-last-action/package.json @@ -28,10 +28,10 @@ "license": "MIT", "peerDependencies": { "reactant-module": "*", - "redux": "^4.1.0" + "redux": "^5.0.1" }, "devDependencies": { "reactant-module": "^0.110.0", - "redux": "^4.1.0" + "redux": "^5.0.1" } } diff --git a/packages/reactant-module/package.json b/packages/reactant-module/package.json index 6fef1a2e3..222d87755 100644 --- a/packages/reactant-module/package.json +++ b/packages/reactant-module/package.json @@ -29,7 +29,7 @@ "dependencies": { "mutative": "^1.0.5", "reactant-di": "^0.110.0", - "redux": "^4.1.0" + "redux": "^5.0.1" }, "devDependencies": { "react": "^17.0.2", diff --git a/packages/reactant-redux/package.json b/packages/reactant-redux/package.json index ba8c2d466..dd59228b1 100644 --- a/packages/reactant-redux/package.json +++ b/packages/reactant-redux/package.json @@ -28,10 +28,10 @@ "license": "MIT", "peerDependencies": { "reactant-module": "*", - "redux": "^4.1.0" + "redux": "^5.0.1" }, "devDependencies": { "reactant-module": "^0.110.0", - "redux": "^4.1.0" + "redux": "^5.0.1" } } diff --git a/packages/reactant-router/package.json b/packages/reactant-router/package.json index efef383e6..b27fc0244 100644 --- a/packages/reactant-router/package.json +++ b/packages/reactant-router/package.json @@ -27,9 +27,9 @@ ], "peerDependencies": { "react": "^16.12.0 || ^17", - "react-redux": "^7.2.8", + "react-redux": "^8.1.3", "reactant-module": "*", - "redux": "^4.1.0" + "redux": "^5.0.1" }, "dependencies": { "connected-react-router": "^6.9.3", @@ -38,9 +38,9 @@ }, "devDependencies": { "react": "^17.0.2", - "react-redux": "^7.2.8", + "react-redux": "^8.1.3", "reactant-module": "^0.110.0", - "redux": "^4.1.0" + "redux": "^5.0.1" }, "license": "MIT" } diff --git a/packages/reactant-storage/package.json b/packages/reactant-storage/package.json index 956614b4d..8abe8f372 100644 --- a/packages/reactant-storage/package.json +++ b/packages/reactant-storage/package.json @@ -29,9 +29,9 @@ "license": "MIT", "peerDependencies": { "react": "^16.12.0 || ^17", - "react-redux": "^7.2.8", + "react-redux": "^8.1.3", "reactant-module": "*", - "redux": "^4.1.0", + "redux": "^5.0.1", "redux-persist": "^6.0.0" }, "dependencies": { @@ -39,8 +39,8 @@ }, "devDependencies": { "react": "^17.0.2", - "react-redux": "^7.2.8", + "react-redux": "^8.1.3", "reactant-module": "^0.110.0", - "redux": "^4.1.0" + "redux": "^5.0.1" } } diff --git a/packages/reactant/package.json b/packages/reactant/package.json index f1254762a..fe0aa998c 100644 --- a/packages/reactant/package.json +++ b/packages/reactant/package.json @@ -36,7 +36,7 @@ "react": "^16.12.0 || ^17" }, "dependencies": { - "react-redux": "^7.2.8", + "react-redux": "^8.1.3", "reactant-module": "^0.110.0" }, "devDependencies": { diff --git a/packages/reactant/src/hooks/useConnector.ts b/packages/reactant/src/hooks/useConnector.ts index 1900675e9..3032c1666 100644 --- a/packages/reactant/src/hooks/useConnector.ts +++ b/packages/reactant/src/hooks/useConnector.ts @@ -47,13 +47,13 @@ import { ShallowEqual } from '../interfaces'; */ export function useConnector( selector: (container: Container) => T, - shallowEqual?: ShallowEqual + shallowEqual?: ShallowEqual ) { try { const container = useContext(ContainerContext); return useSelector( - () => selector(container!) as Record, - shallowEqual || areShallowEqualWithObject + () => selector(container!) as unknown, + (shallowEqual || areShallowEqualWithObject) as any ) as T; } catch (e) { try { diff --git a/packages/reactant/src/interfaces.ts b/packages/reactant/src/interfaces.ts index 77deb0783..8182c3f7c 100644 --- a/packages/reactant/src/interfaces.ts +++ b/packages/reactant/src/interfaces.ts @@ -48,7 +48,4 @@ export interface App> { bootstrap(...args: S): ReturnType | Promise; } -export type ShallowEqual = ( - a: Record, - b: Record -) => boolean; +export type ShallowEqual = (a: T, b: T) => boolean; diff --git a/packages/reactant/test/useConnector.test.tsx b/packages/reactant/test/useConnector.test.tsx index 0ca3d142d..ec1622483 100644 --- a/packages/reactant/test/useConnector.test.tsx +++ b/packages/reactant/test/useConnector.test.tsx @@ -130,6 +130,14 @@ describe('useConnector', () => { @injectable() class FooView extends ViewModule { + @state + count = 0; + + @action + increase() { + this.count += 1; + } + @state key: string | null = null; @@ -143,7 +151,7 @@ describe('useConnector', () => { () => this.key, (newValue, oldValue) => { checkFn(); - throw new Error(`some error`); + return newValue === oldValue; } ); renderFn(value); @@ -164,13 +172,60 @@ describe('useConnector', () => { act(() => { app.bootstrap(container); }); - expect(checkFn).toBeCalledTimes(0); + expect(checkFn).toBeCalledTimes(1); expect(renderFn).toBeCalledTimes(1); - expect(() => { + act(() => { app.instance.setValue('str'); - }).toThrow(); + }); expect(checkFn).toBeCalledTimes(3); - expect(renderFn).toBeCalledTimes(1); + expect(renderFn).toBeCalledTimes(2); + act(() => { + app.instance.increase(); + }); + expect(checkFn).toBeCalledTimes(4); + expect(renderFn).toBeCalledTimes(2); + }); + + test('selector with error custom shallowEqual', () => { + const renderFn = jest.fn(); + const checkFn = jest.fn(); + + @injectable() + class FooView extends ViewModule { + @state + key: string | null = null; + + @action + setValue(value: string) { + this.key = value; + } + + component() { + const value = useConnector( + () => this.key, + (newValue, oldValue) => { + checkFn(); + throw new Error(`some error`); + } + ); + renderFn(value); + return null; + } + } + + const app = createApp({ + modules: [], + main: { + provide: 'FooView', + useClass: FooView, + }, + render, + }); + expect(checkFn).toBeCalledTimes(0); + expect(renderFn).toBeCalledTimes(0); + expect(() => { + app.bootstrap(container); + }).toThrowError('some error'); }); test('selector without store', () => { diff --git a/yarn.lock b/yarn.lock index 29f08563c..7d922c235 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1306,14 +1306,14 @@ dependencies: regenerator-runtime "^0.13.4" -"@babel/runtime@^7.1.2", "@babel/runtime@^7.10.2", "@babel/runtime@^7.12.1", "@babel/runtime@^7.9.2": +"@babel/runtime@^7.1.2", "@babel/runtime@^7.10.2", "@babel/runtime@^7.12.1": version "7.15.3" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.15.3.tgz#2e1c2880ca118e5b2f9988322bd8a7656a32502b" integrity sha512-OvwMLqNXkCXSz1kSm58sEsNuhqOx/fKpnUnKnFB5v8uDda5bLNEHNgKPvhDN6IU0LDcnHQ90LlJ0Q6jnyBSIBA== dependencies: regenerator-runtime "^0.13.4" -"@babel/runtime@^7.12.13", "@babel/runtime@^7.15.4": +"@babel/runtime@^7.12.13": version "7.17.9" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.17.9.tgz#d19fbf802d01a8cb6cf053a64e472d42c434ba72" integrity sha512-lSiBBvodq29uShpWGNbgFdKYNiFDo5/HIYsaCEY9ff4sb10x9jizo2+pRrSyF4jKZCXqgzuqBOQKbUm90gQwJg== @@ -3132,6 +3132,14 @@ "@types/react" "*" hoist-non-react-statics "^3.3.0" +"@types/hoist-non-react-statics@^3.3.1": + version "3.3.5" + resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.5.tgz#dab7867ef789d87e2b4b0003c9d65c49cc44a494" + integrity sha512-SbcrWzkKBw2cdwRTwQAswfpB9g9LJWfjtUeW/jvNwbhC8cpmmNYVePa+ncbUe0rGTQ7G3Ff6mYUN2VMfLVr+Sg== + dependencies: + "@types/react" "*" + hoist-non-react-statics "^3.3.0" + "@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0": version "2.0.1" resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz#42995b446db9a48a11a07ec083499a860e9138ff" @@ -3251,7 +3259,7 @@ dependencies: "@types/react" "*" -"@types/react-redux@^7.1.20", "@types/react-redux@^7.1.24": +"@types/react-redux@^7.1.24": version "7.1.24" resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.24.tgz#6caaff1603aba17b27d20f8ad073e4c077e975c0" integrity sha512-7FkurKcS1k0FHZEtdbbgN8Oc6b+stGSfZYjQGicofJ0j4U0qIn/jaSvnP2pLwZKiai3/17xqqxkkrxTgN8UNbQ== @@ -3314,6 +3322,11 @@ resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.2.tgz#6286b4c7228d58ab7866d19716f3696e03a09397" integrity sha512-Q5vtl1W5ue16D+nIaW8JWebSSraJVlK+EthKn7e7UcD4KWsaSJ8BqGPXNaPghgtcn/fhvrN17Tv8ksUsQpiplw== +"@types/use-sync-external-store@^0.0.3": + version "0.0.3" + resolved "https://registry.yarnpkg.com/@types/use-sync-external-store/-/use-sync-external-store-0.0.3.tgz#b6725d5f4af24ace33b36fafd295136e75509f43" + integrity sha512-EwmlvuaxPNej9+T4v5AuBPJa2x2UOJVdjCtDHgcDqitUeOtjnJKJ+apYjVcAoBEMjKW1VVFGZLUb5+qqa09XFA== + "@types/yargs-parser@*": version "13.1.0" resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-13.1.0.tgz#c563aa192f39350a1d18da36c5a8da382bbd8228" @@ -10616,7 +10629,7 @@ react-is@^16.13.1, react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== -react-is@^17.0.1, react-is@^17.0.2: +react-is@^17.0.1: version "17.0.2" resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== @@ -10664,17 +10677,17 @@ react-native@^0.74.0: ws "^6.2.2" yargs "^17.6.2" -react-redux@^7.2.8: - version "7.2.8" - resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.2.8.tgz#a894068315e65de5b1b68899f9c6ee0923dd28de" - integrity sha512-6+uDjhs3PSIclqoCk0kd6iX74gzrGc3W5zcAjbrFgEdIjRSQObdIwfx80unTkVUYvbQ95Y8Av3OvFHq1w5EOUw== +react-redux@^8.1.3: + version "8.1.3" + resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-8.1.3.tgz#4fdc0462d0acb59af29a13c27ffef6f49ab4df46" + integrity sha512-n0ZrutD7DaX/j9VscF+uTALI3oUPa/pO4Z3soOBIjuRn/FzVu6aehhysxZCLi6y7duMf52WNZGMl7CtuK5EnRw== dependencies: - "@babel/runtime" "^7.15.4" - "@types/react-redux" "^7.1.20" + "@babel/runtime" "^7.12.1" + "@types/hoist-non-react-statics" "^3.3.1" + "@types/use-sync-external-store" "^0.0.3" hoist-non-react-statics "^3.3.2" - loose-envify "^1.4.0" - prop-types "^15.7.2" - react-is "^17.0.2" + react-is "^18.0.0" + use-sync-external-store "^1.0.0" react-refresh@^0.14.0: version "0.14.2" @@ -10927,12 +10940,10 @@ redux@^4.0.0: loose-envify "^1.4.0" symbol-observable "^1.2.0" -redux@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/redux/-/redux-4.1.0.tgz#eb049679f2f523c379f1aff345c8612f294c88d4" - integrity sha512-uI2dQN43zqLWCt6B/BMGRMY6db7TTY4qeHHfGeKb3EOhmOKjU3KdWvNLJyqaHRksv/ErdNH7cFZWg9jXtewy4g== - dependencies: - "@babel/runtime" "^7.9.2" +redux@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/redux/-/redux-5.0.1.tgz#97fa26881ce5746500125585d5642c77b6e9447b" + integrity sha512-M9/ELqF6fy8FwmkpnF0S3YKOqMyoWJ4+CS5Efg2ct3oY9daQvd/Pc71FpGZsVsbl3Cpb+IIcjBDUnnyBdQbq4w== reflect-metadata@^0.1.13: version "0.1.13" @@ -12651,6 +12662,11 @@ use-sync-external-store@1.2.0: resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz#7dbefd6ef3fe4e767a0cf5d7287aacfb5846928a" integrity sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA== +use-sync-external-store@^1.0.0: + version "1.2.2" + resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.2.tgz#c3b6390f3a30eba13200d2302dcdf1e7b57b2ef9" + integrity sha512-PElTlVMwpblvbNqQ82d2n6RjStvdSoNe9FG28kNfz3WiXilJm4DdNkEzRhCZuIDwY8U08WVihhGR5iRqAwfDiw== + use@^3.1.0: version "3.1.1" resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f" From 0ef0fd90e2166f93cb2cfe18c9f15459a20b5b08 Mon Sep 17 00:00:00 2001 From: unadlib Date: Sat, 25 May 2024 17:20:18 +0800 Subject: [PATCH 2/6] fix(type): fix type issue --- packages/reactant-module/src/core/createStore.ts | 6 +++--- packages/reactant-module/src/core/handlePlugin.ts | 7 +++---- packages/reactant-module/src/core/plugin.ts | 12 ++---------- packages/reactant-module/src/decorators/action.ts | 5 +++-- packages/reactant-module/src/interfaces.ts | 5 ++--- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/packages/reactant-module/src/core/createStore.ts b/packages/reactant-module/src/core/createStore.ts index 7235928bd..c86172eda 100644 --- a/packages/reactant-module/src/core/createStore.ts +++ b/packages/reactant-module/src/core/createStore.ts @@ -12,11 +12,11 @@ import { ServiceIdentifiersMap, } from 'reactant-di'; import { + Action, AnyAction, applyMiddleware, combineReducers, createStore as createStoreWithRedux, - PreloadedState, Reducer, ReducersMapObject, } from 'redux'; @@ -66,7 +66,7 @@ interface CreateStoreOptions { load: (...args: Parameters) => void; dynamicModules: DynamicModules; pluginHooks: PluginHooks; - preloadedState?: PreloadedState; + preloadedState?: T; devOptions?: DevOptions; originalStore?: ReactantStore; beforeReplaceReducer?: () => void; @@ -245,7 +245,7 @@ export function createStore({ return action._reactant === actionIdentifier && action.state[identifier!] ? action.state[identifier!][key] - : pureReducer(state, action); + : pureReducer(state, action as AnyAction); }; return Object.assign(serviceReducersMapObject, { [key]: reducer, diff --git a/packages/reactant-module/src/core/handlePlugin.ts b/packages/reactant-module/src/core/handlePlugin.ts index 2e73f81f3..40a59cd1d 100644 --- a/packages/reactant-module/src/core/handlePlugin.ts +++ b/packages/reactant-module/src/core/handlePlugin.ts @@ -1,4 +1,4 @@ -import { ReducersMapObject, Reducer, PreloadedState } from 'redux'; +import type { ReducersMapObject, Reducer } from 'redux'; import { PluginModule } from './plugin'; import { PluginHooks, HandlePlugin } from '../interfaces'; @@ -19,9 +19,8 @@ export const handlePlugin: HandlePlugin = ( ); } if (typeof service.preloadedStateHandler === 'function') { - pluginHooks.preloadedStateHandler.push( - (preloadedState: PreloadedState) => - service.preloadedStateHandler!(preloadedState) + pluginHooks.preloadedStateHandler.push((preloadedState: any) => + service.preloadedStateHandler!(preloadedState) ); } if (typeof service.enhancer === 'function') { diff --git a/packages/reactant-module/src/core/plugin.ts b/packages/reactant-module/src/core/plugin.ts index 379504aec..2a54dbff0 100644 --- a/packages/reactant-module/src/core/plugin.ts +++ b/packages/reactant-module/src/core/plugin.ts @@ -1,11 +1,5 @@ import type { FunctionComponent } from 'react'; -import type { - ReducersMapObject, - Middleware, - PreloadedState, - Reducer, - Store, -} from 'redux'; +import type { ReducersMapObject, Middleware, Reducer, Store } from 'redux'; import { injectable } from 'reactant-di'; import { storeKey } from '../constants'; import { Service } from '../interfaces'; @@ -17,9 +11,7 @@ abstract class PluginModule implements Service { /** * preloaded state handler for Redux */ - preloadedStateHandler?( - preloadedState: PreloadedState - ): PreloadedState; + preloadedStateHandler?(preloadedState: any): any; /** * inject middleware for Redux diff --git a/packages/reactant-module/src/decorators/action.ts b/packages/reactant-module/src/decorators/action.ts index 949ef60c6..00c3fbcd1 100644 --- a/packages/reactant-module/src/decorators/action.ts +++ b/packages/reactant-module/src/decorators/action.ts @@ -1,7 +1,8 @@ /* eslint-disable no-console */ /* eslint-disable func-names */ import { create } from 'mutative'; -import { Patches, ReactantAction, Service } from '../interfaces'; +import type { AnyAction } from 'redux'; +import type { Patches, Service } from '../interfaces'; import { storeKey, actionIdentifier, @@ -116,7 +117,7 @@ const action = ( ); } } - this[storeKey]!.dispatch({ + this[storeKey]!.dispatch({ type: this[identifierKey]!, method: key, params: args, diff --git a/packages/reactant-module/src/interfaces.ts b/packages/reactant-module/src/interfaces.ts index 0a33611c3..d5aabdaae 100644 --- a/packages/reactant-module/src/interfaces.ts +++ b/packages/reactant-module/src/interfaces.ts @@ -1,7 +1,6 @@ /* eslint-disable no-use-before-define */ import type { Store as ReduxStore, - PreloadedState, AnyAction, Middleware, Action, @@ -78,7 +77,7 @@ export type ReduxDevToolsOptions = Pick< Exclude >; -export type TypePreloadedState = PreloadedState; +export type TypePreloadedState = T; export type Subscriptions = (() => void)[]; @@ -112,7 +111,7 @@ export type ReactantStore = ReduxStore & { export type ReactantMiddleware = Middleware; -export interface ReactantAction extends Action { +export interface ReactantAction extends Action { method?: string; state: Record; params: any[]; From a59d993b4c2103f328451f7144bf5cbfa93d7a9d Mon Sep 17 00:00:00 2001 From: unadlib Date: Sat, 25 May 2024 17:30:48 +0800 Subject: [PATCH 3/6] fix(type): fix router type issue --- packages/reactant-router/src/router.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/reactant-router/src/router.tsx b/packages/reactant-router/src/router.tsx index bffbac549..9ba61e703 100644 --- a/packages/reactant-router/src/router.tsx +++ b/packages/reactant-router/src/router.tsx @@ -1,12 +1,11 @@ /* eslint-disable consistent-return */ import React, { PropsWithChildren, FunctionComponent } from 'react'; import { PluginModule, injectable, inject, storeKey } from 'reactant-module'; -import type { ReducersMapObject, Store } from 'redux'; +import type { AnyAction, ReducersMapObject } from 'redux'; import { connectRouter, ConnectedRouter, CALL_HISTORY_METHOD, - RouterAction, onLocationChanged, routerActions, } from 'connected-react-router'; @@ -66,7 +65,8 @@ class ReactantRouter extends PluginModule { this.autoCreateHistory = this.options?.autoCreateHistory ?? true; if (this.autoCreateHistory) { this.history = this.options.createHistory(); - this.middleware = (store) => (next) => (action: RouterAction) => { + this.middleware = (store) => (next) => (_action) => { + const action = _action as AnyAction; if (action.type !== CALL_HISTORY_METHOD) { return next(action); } @@ -113,23 +113,23 @@ class ReactantRouter extends PluginModule { } push(path: string, state?: LocationState) { - this.store?.dispatch(this.routerActions.push(path, state)); + this.store?.dispatch(this.routerActions.push(path, state) as AnyAction); } replace(path: string, state?: LocationState) { - this.store?.dispatch(this.routerActions.replace(path, state)); + this.store?.dispatch(this.routerActions.replace(path, state) as AnyAction); } go(n: number) { - this.store?.dispatch(this.routerActions.go(n)); + this.store?.dispatch(this.routerActions.go(n) as AnyAction); } goBack() { - this.store?.dispatch(this.routerActions.goBack()); + this.store?.dispatch(this.routerActions.goBack() as AnyAction); } goForward() { - this.store?.dispatch(this.routerActions.goForward()); + this.store?.dispatch(this.routerActions.goForward() as AnyAction); } provider = (props: PropsWithChildren) => { From e9e36d32fe473ba38b5ee82b717d1bcabda6edb7 Mon Sep 17 00:00:00 2001 From: unadlib Date: Sat, 25 May 2024 17:35:24 +0800 Subject: [PATCH 4/6] fix(type): fix reactant-share type issue --- packages/reactant-share/src/modules/coworker.ts | 3 ++- packages/reactant-share/src/modules/patchesChecker.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/reactant-share/src/modules/coworker.ts b/packages/reactant-share/src/modules/coworker.ts index 67ab4fb03..b2f824ffc 100644 --- a/packages/reactant-share/src/modules/coworker.ts +++ b/packages/reactant-share/src/modules/coworker.ts @@ -116,7 +116,8 @@ export class Coworker extends PluginModule { if (this.isCoworker && this.enablePatchesChecker) { // stricter checks to prevent cross-module state updates. - this.middleware = (store) => (next) => (_action: ReactantAction) => { + this.middleware = (store) => (next) => (action) => { + const _action = action as ReactantAction; const { _patches, type, method } = _action; // skip check for storage module change any state if (type === storageModuleName) return next(_action); diff --git a/packages/reactant-share/src/modules/patchesChecker.ts b/packages/reactant-share/src/modules/patchesChecker.ts index 0dc149a10..fc9da05af 100644 --- a/packages/reactant-share/src/modules/patchesChecker.ts +++ b/packages/reactant-share/src/modules/patchesChecker.ts @@ -36,7 +36,8 @@ export class PatchesChecker extends PluginModule { } } - middleware: Middleware = (store) => (next) => (_action: ReactantAction) => { + middleware: Middleware = (store) => (next) => (action) => { + const _action = action as ReactantAction; const { _patches, type, method } = _action; let hasIsolatedState: boolean; _patches?.forEach(({ path, op, value }, index) => { From 48c02bd1235849bb5649a42480e700d2daa9eff6 Mon Sep 17 00:00:00 2001 From: unadlib Date: Sat, 25 May 2024 17:46:22 +0800 Subject: [PATCH 5/6] fix(type): update --- packages/reactant-redux/test/index.test.ts | 5 ++--- packages/reactant-share/src/modules/router.ts | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/reactant-redux/test/index.test.ts b/packages/reactant-redux/test/index.test.ts index 5df0dfbcd..2cbb8ece3 100644 --- a/packages/reactant-redux/test/index.test.ts +++ b/packages/reactant-redux/test/index.test.ts @@ -5,7 +5,6 @@ import { createContainer, createStore, } from 'reactant-module'; -import { Dispatch } from 'redux'; import { redux } from '..'; test('base redux with `useValue`', () => { @@ -38,7 +37,7 @@ test('base redux with `useValue`', () => { action.type === 'add' ? [...state, action.payload] : state, }, actions: { - add: (text: string) => (dispatch: Dispatch) => + add: (text: string) => (dispatch) => dispatch({ type: 'add', payload: { text, completed: false }, @@ -133,7 +132,7 @@ test('base redux with `useFactory`', () => { ) => (action.type === 'add' ? [...state, action.payload] : state), }, actions: { - add: (text: string) => (dispatch: Dispatch) => + add: (text: string) => (dispatch) => dispatch({ type: 'add', payload: { text, completed: false }, diff --git a/packages/reactant-share/src/modules/router.ts b/packages/reactant-share/src/modules/router.ts index 8f39bc004..85555b0f1 100644 --- a/packages/reactant-share/src/modules/router.ts +++ b/packages/reactant-share/src/modules/router.ts @@ -16,6 +16,7 @@ import type { RouterState, } from 'reactant-router'; import type { LocationState } from 'history'; +import type { AnyAction } from 'redux'; import { routerModuleName, SharedAppOptions, @@ -391,7 +392,7 @@ class ReactantRouter extends BaseReactantRouter { protected dispatchChanged(router: RouterState) { this.store?.dispatch( - this.onLocationChanged(router.location, router.action)! + this.onLocationChanged(router.location, router.action) as AnyAction ); } From 79fd2542672e3cf890ac47d859bde1de4509cc98 Mon Sep 17 00:00:00 2001 From: unadlib Date: Sat, 25 May 2024 17:49:52 +0800 Subject: [PATCH 6/6] fix(type): fix type --- packages/reactant-model/src/model.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/reactant-model/src/model.ts b/packages/reactant-model/src/model.ts index 1c772e736..c8fcd47d7 100644 --- a/packages/reactant-model/src/model.ts +++ b/packages/reactant-model/src/model.ts @@ -62,7 +62,7 @@ export const model = < } const lastState = module[storeKey]?.getState(); module[storeKey]!.dispatch({ - type: module[identifierKey], + type: module[identifierKey]!, method: key, state: { ...lastState,