Skip to content

Commit

Permalink
fix: remove reach/router dep if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
salvoravida committed Jun 17, 2022
1 parent 9e221fd commit 328cf16
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-first-history",
"version": "5.0.9",
"version": "5.0.10",
"description": "Redux First History - Redux history binding support react-router - @reach/router - wouter",
"main": "build/es5/index.js",
"module": "build/es6/index.js",
Expand Down Expand Up @@ -50,7 +50,7 @@
"@testing-library/react": "^12.1.0",
"@types/history": "^4.7.9",
"@types/jest": "^27.0.2",
"@types/reach__router": "^1.3.9",
"@types/reach__router": "^1.3.10",
"@types/react": "^17.0.24",
"@typescript-eslint/eslint-plugin": "^4.31.2",
"@typescript-eslint/parser": "^4.31.2",
Expand Down
2 changes: 1 addition & 1 deletion src/create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { History, Location } from 'history';
import type { History as ReachHistory } from '@reach/router';
import type { Middleware, Reducer, Store } from 'redux';
import type { ReachHistory } from './reachify.types';
import {
go,
goBack,
Expand Down
2 changes: 1 addition & 1 deletion src/reachify.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line import/no-unresolved
import { History as ReachHistory } from '@reach/router';
import { History } from 'history';
import { ReachHistory } from './reachify.types';

export const reachify = (reduxHistory: History & { listenObject: boolean }): ReachHistory => {
let transitioning = false;
Expand Down
40 changes: 40 additions & 0 deletions src/reachify.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/reach__router/index.d.ts
/**
* cloning reach router types so the packages does not depends on reach/router types if not used.
* to be removed in v6 and deprecate reach-router
*/

interface HLocation<S = unknown> {
pathname: string;
search: string;
state: S;
hash: string;
key?: string | undefined;
}
type WindowLocation<S = unknown> = Window['location'] & HLocation<S>;

type HistoryActionType = 'PUSH' | 'POP';
type HistoryLocation = WindowLocation & { state?: any };
interface HistoryListenerParameter {
location: HistoryLocation;
action: HistoryActionType;
}
type HistoryListener = (parameter: HistoryListenerParameter) => void;
type HistoryUnsubscribe = () => void;

interface NavigateOptions<TState> {
state?: TState | undefined;
replace?: boolean | undefined;
}
interface NavigateFn {
// eslint-disable-next-line @typescript-eslint/ban-types
(to: string, options?: NavigateOptions<{}>): Promise<void>;
(to: number): Promise<void>;
}

export interface ReachHistory {
readonly location: HistoryLocation;
readonly transitioning: boolean;
listen: (listener: HistoryListener) => HistoryUnsubscribe;
navigate: NavigateFn;
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -751,10 +751,10 @@
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11"
integrity sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ==

"@types/reach__router@^1.3.9":
version "1.3.9"
resolved "https://registry.yarnpkg.com/@types/reach__router/-/reach__router-1.3.9.tgz#d3aaac0072665c81063cc6c557c18dadd642b226"
integrity sha512-N6rqQqTTAV/zKLfK3iq9Ww3wqCEhTZvsilhl0zI09zETdVq1QGmJH6+/xnj8AFUWIrle2Cqo+PGM/Ltr1vBb9w==
"@types/reach__router@^1.3.10":
version "1.3.10"
resolved "https://registry.yarnpkg.com/@types/reach__router/-/reach__router-1.3.10.tgz#141d500213a452d9d9d71d5ad96c4104094f55a3"
integrity sha512-iHAFGaVOrWi00/q7oBybggGsz5TOmwOW4M1H9sT7i9lly4qFC8XOgsdf6jUsoaOz2sknFHALEtZqCoDbokdJ2Q==
dependencies:
"@types/react" "*"

Expand Down

0 comments on commit 328cf16

Please sign in to comment.