From 040c1365bc12314f7ce49799cd2cdcb8e6c295f5 Mon Sep 17 00:00:00 2001 From: Karol Janyst Date: Tue, 17 Jan 2017 12:32:34 +0900 Subject: [PATCH] Update react-router-redux to user history 4.5.x --- react-router-redux/index.d.ts | 111 ++++++++---------- .../react-router-redux-tests.ts | 20 +++- react-router-redux/tsconfig.json | 17 ++- react-router-redux/tslint.json | 1 + 4 files changed, 76 insertions(+), 73 deletions(-) create mode 100644 react-router-redux/tslint.json diff --git a/react-router-redux/index.d.ts b/react-router-redux/index.d.ts index 16438f9452..a6d3bd8c00 100644 --- a/react-router-redux/index.d.ts +++ b/react-router-redux/index.d.ts @@ -1,65 +1,58 @@ -// Type definitions for react-router-redux v4.0.0 +// Type definitions for react-router-redux 4.0 // Project: https://github.com/rackt/react-router-redux -// Definitions by: Isman Usoh , Noah Shipley , Dimitri Rosenberg +// Definitions by: Isman Usoh , Noah Shipley , Dimitri Rosenberg , Karol Janyst // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// +import { Action, Middleware, Store } from "redux"; +import { History, Location, LocationDescriptor } from "history"; -import * as Redux from "redux"; -import * as History from "history"; +export const CALL_HISTORY_METHOD: string; +export const LOCATION_CHANGE: string; -export = ReactRouterRedux; - -declare namespace ReactRouterRedux { - import R = Redux; - - const CALL_HISTORY_METHOD: string; - const LOCATION_CHANGE: string; - - const push: PushAction; - const replace: ReplaceAction; - const go: GoAction; - const goBack: GoForwardAction; - const goForward: GoBackAction; - const routerActions: RouteActions; - - type LocationDescriptor = History.LocationDescriptor; - type PushAction = (nextLocation: LocationDescriptor) => RouterAction; - type ReplaceAction = (nextLocation: LocationDescriptor) => RouterAction; - type GoAction = (n: number) => RouterAction; - type GoForwardAction = () => RouterAction; - type GoBackAction = () => RouterAction; - - type RouterAction = { - type: string - payload?: LocationDescriptor - } - - interface RouteActions { - push: PushAction; - replace: ReplaceAction; - go: GoAction; - goForward: GoForwardAction; - goBack: GoBackAction; - } - interface ReactRouterReduxHistory extends History.History { - unsubscribe(): void; - } - - interface DefaultSelectLocationState extends Function { - (state: any): any; - } - - interface SyncHistoryWithStoreOptions { - selectLocationState?: DefaultSelectLocationState; - adjustUrlOnReplay?: boolean; - } - - interface RouterState { - locationBeforeTransitions: History.Location - } - - function routerReducer(state?: RouterState, action?: R.Action): RouterState; - function syncHistoryWithStore(history: History.History, store: R.Store, options?: SyncHistoryWithStoreOptions): ReactRouterReduxHistory; - function routerMiddleware(history: History.History): R.Middleware; +export interface LocationActionPayload { + method: string; + args?: any[]; } + +export interface RouterAction extends Action { + payload?: LocationActionPayload; +} + +type LocationAction = (nextLocation: LocationDescriptor) => RouterAction; +type GoAction = (n: number) => RouterAction; +type NavigateAction = () => RouterAction; + +export const push: LocationAction; +export const replace: LocationAction; +export const go: GoAction; +export const goBack: NavigateAction; +export const goForward: NavigateAction; + +interface RouteActions { + push: typeof push; + replace: typeof replace; + go: typeof go; + goForward: typeof goForward; + goBack: typeof goBack; +} + +export const routerActions: RouteActions; + +export interface RouterState { + locationBeforeTransitions: Location +} + +export type DefaultSelectLocationState = (state: any) => RouterState + +export interface SyncHistoryWithStoreOptions { + selectLocationState?: DefaultSelectLocationState; + adjustUrlOnReplay?: boolean; +} + +export interface HistoryUnsubscribe { + unsubscribe(): void; +} + +export function routerReducer(state?: RouterState, action?: Action): RouterState; +export function syncHistoryWithStore(history: History, store: Store, options?: SyncHistoryWithStoreOptions): History & HistoryUnsubscribe; +export function routerMiddleware(history: History): Middleware; diff --git a/react-router-redux/react-router-redux-tests.ts b/react-router-redux/react-router-redux-tests.ts index 1d73706c4e..87b99b2a69 100644 --- a/react-router-redux/react-router-redux-tests.ts +++ b/react-router-redux/react-router-redux-tests.ts @@ -1,9 +1,16 @@ -/// -/// - import { createStore, combineReducers, applyMiddleware } from 'redux'; import { browserHistory } from 'react-router'; -import { syncHistoryWithStore, routerReducer, routerMiddleware, push, replace, go, goForward, goBack } from 'react-router-redux'; +import { + syncHistoryWithStore, + routerReducer, + routerMiddleware, + push, + replace, + go, + goForward, + goBack, + routerActions +} from 'react-router-redux'; const reducer = combineReducers({ routing: routerReducer }); @@ -25,3 +32,8 @@ store.dispatch(replace('/foo')); store.dispatch(go(1)); store.dispatch(goForward()); store.dispatch(goBack()); +store.dispatch(routerActions.push('/foo')); +store.dispatch(routerActions.replace('/foo')); +store.dispatch(routerActions.go(1)); +store.dispatch(routerActions.goForward()); +store.dispatch(routerActions.goBack()); diff --git a/react-router-redux/tsconfig.json b/react-router-redux/tsconfig.json index b2efdcc111..64b2c38849 100644 --- a/react-router-redux/tsconfig.json +++ b/react-router-redux/tsconfig.json @@ -1,23 +1,20 @@ { - "files": [ - "index.d.ts", - "react-router-redux-tests.ts" - ], "compilerOptions": { "module": "commonjs", "target": "es6", "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", - "paths": { - "history": ["history/v2"] - }, "typeRoots": [ - "../" + "../" ], "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true - } + }, + "files": [ + "index.d.ts", + "react-router-redux-tests.ts" + ] } diff --git a/react-router-redux/tslint.json b/react-router-redux/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/react-router-redux/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }