Skip to content

Commit

Permalink
support redux 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
salvoravida committed Dec 14, 2023
1 parent 2bf677a commit cb621ed
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"prettier": "^3.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"redux": "^4.2.1",
"redux": "^5.0.0",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
Expand Down
3 changes: 2 additions & 1 deletion src/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Location, Action, History } from 'history';
import type { AnyAction } from 'redux';

export const CALL_HISTORY_METHOD = '@@router/CALL_HISTORY_METHOD';
export const LOCATION_CHANGE = '@@router/LOCATION_CHANGE';
Expand All @@ -23,7 +24,7 @@ export interface LocationActionPayload<A = unknown[]> {
args?: A;
}

export interface CallHistoryMethodAction<A = unknown[]> {
export interface CallHistoryMethodAction<A = unknown[]> extends AnyAction {
type: typeof CALL_HISTORY_METHOD;
payload: LocationActionPayload<A>;
}
Expand Down
2 changes: 2 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ function appendBasename(location: string | Location, basename: string): string |
export const createRouterMiddleware =
({ history, showHistoryAction, basename }: CreateRouterMiddlewareArgs): Middleware =>
() =>
// @ts-ignore
(next: Dispatch) =>
(action: ReduxAction) => {
if (action.type !== CALL_HISTORY_METHOD) {
return next(action);
}
// @ts-ignore
const method = action.payload.method as HistoryMethods;
// @ts-ignore
const args = action.payload.args as Parameters<History[HistoryMethods]>;
Expand Down
5 changes: 4 additions & 1 deletion src/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export const createRouterReducer = ({

return (state = initialState, { type, payload } = {} as AnyAction) => {
if (type === LOCATION_CHANGE) {
const { location, action } = payload || {};
const { location, action } = (payload || {}) as {
location?: Location | null;
action?: Action | null;
};
const previousLocations = numLocationToTrack // @ts-ignore
? [{ location, action }, ...state.previousLocations.slice(0, numLocationToTrack)]
: undefined;
Expand Down
12 changes: 5 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@
dependencies:
regenerator-runtime "^0.13.4"

"@babel/runtime@^7.12.5", "@babel/runtime@^7.9.2":
"@babel/runtime@^7.12.5":
version "7.16.0"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.16.0.tgz#e27b977f2e2088ba24748bf99b5e1dece64e4f0b"
integrity sha512-Nht8L0O8YCktmsDV6FqFue7vQLRx3Hb0B37lS5y0jDRqRxlBG4wIJHnf9/bgSE2UyipKFA01YtS+npRdTWBUyw==
Expand Down Expand Up @@ -4386,12 +4386,10 @@ react@^18.2.0:
dependencies:
loose-envify "^1.1.0"

redux@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/redux/-/redux-4.2.1.tgz#c08f4306826c49b5e9dc901dee0452ea8fce6197"
integrity sha512-LAUYz4lc+Do8/g7aeRa8JkyDErK6ekstQaqWQrNRW//MY1TvCEpMtpTWvlQ+FPbWCx+Xixu/6SHt5N0HR+SB4w==
dependencies:
"@babel/runtime" "^7.9.2"
redux@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/redux/-/redux-5.0.0.tgz#29572e29a439e094ff8fec46883fc45053f6736d"
integrity sha512-blLIYmYetpZMET6Q6uCY7Jtl/Im5OBldy+vNPauA8vvsdqyt66oep4EUpAMWNHauTC6xa9JuRPhRB72rY82QGA==

reflect.getprototypeof@^1.0.4:
version "1.0.4"
Expand Down

0 comments on commit cb621ed

Please sign in to comment.