mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-13 05:20:25 +00:00
Merge pull request #8231 from isman-usoh/react-router-redux-patch-1
update react-router-redux version 4
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
/// <reference path="./react-router-redux-2.x.d.ts" />
|
||||
/// <reference path="../redux/redux.d.ts" />
|
||||
/// <reference path="../react-router/react-router.d.ts" />
|
||||
|
||||
|
||||
|
||||
import { createStore, combineReducers, applyMiddleware } from 'redux';
|
||||
import { browserHistory } from 'react-router';
|
||||
import { syncHistory, routeReducer } from 'react-router-redux';
|
||||
|
||||
const reducer = combineReducers({ routing: routeReducer });
|
||||
|
||||
// Sync dispatched route actions to the history
|
||||
const reduxRouterMiddleware = syncHistory(browserHistory);
|
||||
const createStoreWithMiddleware = applyMiddleware(reduxRouterMiddleware)(createStore);
|
||||
|
||||
const store = createStoreWithMiddleware(reducer);
|
||||
|
||||
// Required for replaying actions from devtools to
|
||||
reduxRouterMiddleware.listenForReplays(store);
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
// Type definitions for react-router-redux v2.x - v3.x
|
||||
// Project: https://github.com/rackt/react-router-redux
|
||||
// Definitions by: Isman Usoh <http://github.com/isman-usoh>, Noah Shipley <https://github.com/noah79>, Dimitri Rosenberg <https://github.com/rosendi>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../redux/redux.d.ts" />
|
||||
/// <reference path="../react-router/react-router.d.ts"/>
|
||||
|
||||
declare namespace ReactRouterRedux {
|
||||
import R = Redux;
|
||||
import H = HistoryModule;
|
||||
|
||||
const TRANSITION: string;
|
||||
const UPDATE_LOCATION: string;
|
||||
|
||||
const push: PushAction;
|
||||
const replace: ReplaceAction;
|
||||
const go: GoAction;
|
||||
const goBack: GoForwardAction;
|
||||
const goForward: GoBackAction;
|
||||
const routeActions: RouteActions;
|
||||
|
||||
type LocationDescriptor = H.Location | H.Path;
|
||||
type PushAction = (nextLocation: LocationDescriptor) => void;
|
||||
type ReplaceAction = (nextLocation: LocationDescriptor) => void;
|
||||
type GoAction = (n: number) => void;
|
||||
type GoForwardAction = () => void;
|
||||
type GoBackAction = () => void;
|
||||
|
||||
interface RouteActions {
|
||||
push: PushAction;
|
||||
replace: ReplaceAction;
|
||||
go: GoAction;
|
||||
goForward: GoForwardAction;
|
||||
goBack: GoBackAction;
|
||||
}
|
||||
interface HistoryMiddleware extends R.Middleware {
|
||||
listenForReplays(store: R.Store, selectLocationState?: Function): void;
|
||||
unsubscribe(): void;
|
||||
}
|
||||
|
||||
function routeReducer(state?: any, options?: any): R.Reducer;
|
||||
function syncHistory(history: H.History): HistoryMiddleware;
|
||||
}
|
||||
|
||||
declare module "react-router-redux" {
|
||||
export = ReactRouterRedux;
|
||||
}
|
||||
@@ -6,15 +6,25 @@
|
||||
|
||||
import { createStore, combineReducers, applyMiddleware } from 'redux';
|
||||
import { browserHistory } from 'react-router';
|
||||
import { syncHistory, routeReducer } from 'react-router-redux';
|
||||
import { syncHistoryWithStore, routerReducer, routerMiddleware, push, replace, go, goForward, goBack } from 'react-router-redux';
|
||||
|
||||
const reducer = combineReducers({ routing: routeReducer });
|
||||
const reducer = combineReducers({ routing: routerReducer });
|
||||
|
||||
// Sync dispatched route actions to the history
|
||||
const reduxRouterMiddleware = syncHistory(browserHistory);
|
||||
const createStoreWithMiddleware = applyMiddleware(reduxRouterMiddleware)(createStore);
|
||||
// Apply the middleware to the store
|
||||
const middleware = routerMiddleware(browserHistory);
|
||||
const store = createStore(
|
||||
reducer,
|
||||
applyMiddleware(middleware)
|
||||
);
|
||||
|
||||
const store = createStoreWithMiddleware(reducer);
|
||||
// Create an enhanced history that syncs navigation events with the store
|
||||
const history = syncHistoryWithStore(browserHistory, store);
|
||||
history.listen(location => console.log(location) );
|
||||
history.unsubscribe();
|
||||
|
||||
// Required for replaying actions from devtools to
|
||||
reduxRouterMiddleware.listenForReplays(store);
|
||||
// Dispatch from anywhere like normal.
|
||||
store.dispatch(push('/foo'));
|
||||
store.dispatch(replace('/foo'));
|
||||
store.dispatch(go(1));
|
||||
store.dispatch(goForward());
|
||||
store.dispatch(goBack());
|
||||
|
||||
+27
-13
@@ -1,4 +1,4 @@
|
||||
// Type definitions for react-router-redux v2.1.0
|
||||
// Type definitions for react-router-redux v4.0.0
|
||||
// Project: https://github.com/rackt/react-router-redux
|
||||
// Definitions by: Isman Usoh <http://github.com/isman-usoh>, Noah Shipley <https://github.com/noah79>, Dimitri Rosenberg <https://github.com/rosendi>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
@@ -10,23 +10,28 @@ declare namespace ReactRouterRedux {
|
||||
import R = Redux;
|
||||
import H = HistoryModule;
|
||||
|
||||
const TRANSITION: string;
|
||||
const UPDATE_LOCATION: string;
|
||||
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 routeActions: RouteActions;
|
||||
const routerActions: RouteActions;
|
||||
|
||||
type LocationDescriptor = H.Location | H.Path;
|
||||
type PushAction = (nextLocation: LocationDescriptor) => void;
|
||||
type ReplaceAction = (nextLocation: LocationDescriptor) => void;
|
||||
type GoAction = (n: number) => void;
|
||||
type GoForwardAction = () => void;
|
||||
type GoBackAction = () => void;
|
||||
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?: any
|
||||
}
|
||||
|
||||
interface RouteActions {
|
||||
push: PushAction;
|
||||
replace: ReplaceAction;
|
||||
@@ -34,13 +39,22 @@ declare namespace ReactRouterRedux {
|
||||
goForward: GoForwardAction;
|
||||
goBack: GoBackAction;
|
||||
}
|
||||
interface HistoryMiddleware extends R.Middleware {
|
||||
listenForReplays(store: R.Store, selectLocationState?: Function): void;
|
||||
interface ReactRouterReduxHistory extends H.History {
|
||||
unsubscribe(): void;
|
||||
}
|
||||
|
||||
interface DefaultSelectLocationState extends Function {
|
||||
(state: any): any;
|
||||
}
|
||||
|
||||
function routeReducer(state?: any, options?: any): R.Reducer;
|
||||
function syncHistory(history: H.History): HistoryMiddleware;
|
||||
interface SyncHistoryWithStoreOptions {
|
||||
selectLocationState?: DefaultSelectLocationState;
|
||||
adjustUrlOnReplay?: boolean;
|
||||
}
|
||||
|
||||
function routerReducer(state?: any, options?: any): R.Reducer;
|
||||
function syncHistoryWithStore(history: H.History, store: R.Store, options?: SyncHistoryWithStoreOptions): ReactRouterReduxHistory;
|
||||
function routerMiddleware(history: H.History): R.Middleware;
|
||||
}
|
||||
|
||||
declare module "react-router-redux" {
|
||||
|
||||
Reference in New Issue
Block a user