mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 15:57:13 +00:00
Fixed some missing definitions
This commit is contained in:
Vendored
+70
-23
@@ -3,20 +3,30 @@
|
||||
// Definitions by: Valbrand <https://github.com/Valbrand>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import { Dispatch, Store } from 'redux'
|
||||
import {
|
||||
Dispatch,
|
||||
Store,
|
||||
Reducer,
|
||||
Middleware,
|
||||
GenericStoreEnhancer
|
||||
} from 'redux'
|
||||
|
||||
interface StateGetter {
|
||||
<S>(): S
|
||||
interface StateGetter<S> {
|
||||
(): S
|
||||
}
|
||||
|
||||
export type RouteString = string
|
||||
|
||||
export interface RouteThunk {
|
||||
<S>(dispatch: Dispatch<S>, getState: StateGetter<S>): any | Promise<any>
|
||||
}
|
||||
|
||||
export interface RouteObject {
|
||||
path: string
|
||||
capitalizedWords?: boolean
|
||||
toPath?: (param: string, key?: string) => string
|
||||
fromPath?: (path: string, key?: string) => string
|
||||
thunk?: <S>(dispatch: Dispatch<S>, getState: StateGetter) => any | Promise<any>
|
||||
toPath?(param: string, key?: string): string
|
||||
fromPath?(path: string, key?: string): string
|
||||
thunk?: RouteThunk
|
||||
navKey?: string
|
||||
}
|
||||
|
||||
@@ -45,6 +55,17 @@ export interface Location {
|
||||
payload: Object
|
||||
}
|
||||
|
||||
export interface LocationState {
|
||||
pathname: string
|
||||
type: string
|
||||
payload: Object
|
||||
prev: Location
|
||||
kind: string | void
|
||||
history: HistoryData | void
|
||||
routesMap: RoutesMap
|
||||
hasSSR?: boolean
|
||||
}
|
||||
|
||||
export interface ActionMetaLocation {
|
||||
current: Location
|
||||
prev: Location
|
||||
@@ -76,18 +97,40 @@ export interface Action {
|
||||
navKey?: string
|
||||
}
|
||||
|
||||
// FIXME
|
||||
export interface History {
|
||||
export interface HistoryLocation {
|
||||
pathname: string
|
||||
}
|
||||
|
||||
export type HistoryAction = string
|
||||
|
||||
export interface Listener {
|
||||
(location: HistoryLocation, action: HistoryAction): void
|
||||
}
|
||||
|
||||
export interface History {
|
||||
listen(listener: Listener): void
|
||||
push(pathname: string): void
|
||||
replace(pathname: string): void
|
||||
goBack(): void
|
||||
goForward(): void
|
||||
go(n: number): void
|
||||
canGo(n: number): boolean
|
||||
|
||||
entries: Array<{ pathname: string }>
|
||||
index: number
|
||||
length: number
|
||||
location: {
|
||||
pathname: string
|
||||
}
|
||||
}
|
||||
|
||||
export type ScrollBehavior = Object
|
||||
|
||||
export interface Router {
|
||||
getStateForActionOriginal: (action: Object, state: Object | void) => Object | void
|
||||
getStateForAction: (action: Object, state: Object | void) => Object | void
|
||||
getPathAndParamsForState: (state: Object) => { path: string | void, params: Object | void }
|
||||
getActionForPathAndParams: (path: string) => Object | void
|
||||
getStateForActionOriginal(action: Object, state: Object | void): Object | void
|
||||
getStateForAction(action: Object, state: Object | void): Object | void
|
||||
getPathAndParamsForState(state: Object): { path: string | void, params: Object | void }
|
||||
getActionForPathAndParams(path: string): Object | void
|
||||
}
|
||||
|
||||
export interface Navigator {
|
||||
@@ -100,20 +143,20 @@ export interface Navigators {
|
||||
|
||||
export interface NavigatorsConfig {
|
||||
navigators: Navigators
|
||||
patchNavigators: (navigators: Navigators) => void
|
||||
patchNavigators(navigators: Navigators): void
|
||||
|
||||
actionToNavigation: (
|
||||
actionToNavigation(
|
||||
navigators: Navigators,
|
||||
action: Object, // TODO check this
|
||||
navigationAction: NavigationAction | void,
|
||||
route: Route | void
|
||||
) => Object
|
||||
navigationToAction: <S>(
|
||||
): Object
|
||||
navigationToAction<S>(
|
||||
navigators: Navigators,
|
||||
store: Store<S>,
|
||||
routesMap: RoutesMap,
|
||||
action: Object
|
||||
) => {
|
||||
): {
|
||||
action: Object,
|
||||
navigationAction: NavigationAction | void
|
||||
}
|
||||
@@ -124,10 +167,10 @@ export interface Options {
|
||||
location?: string
|
||||
notFoundPath?: string
|
||||
scrollTop?: boolean
|
||||
onBeforeChange?: <S>(dispatch: Dispatch<S>, getState: StateGetter) => void
|
||||
onAfterChange?: <S>(dispatch: Dispatch<S>, getState: StateGetter) => void
|
||||
onBackNext?: <S>(dispatch: Dispatch<S>, getState: StateGetter) => void
|
||||
restoreScroll?: (history: History) => ScrollBehavior
|
||||
onBeforeChange?: <S>(dispatch: Dispatch<S>, getState: StateGetter<S>) => void
|
||||
onAfterChange?: <S>(dispatch: Dispatch<S>, getState: StateGetter<S>) => void
|
||||
onBackNext?: <S>(dispatch: Dispatch<S>, getState: StateGetter<S>) => void
|
||||
restoreScroll?(history: History): ScrollBehavior
|
||||
navigators?: NavigatorsConfig
|
||||
}
|
||||
|
||||
@@ -145,8 +188,12 @@ export function canGoBack(): boolean;
|
||||
|
||||
export function canGoForward(): boolean;
|
||||
|
||||
// FIXME
|
||||
export function connectRoutes(history: History, routesMap: RoutesMap, options: Options): any;
|
||||
export function connectRoutes(history: History, routesMap: RoutesMap, options?: Options): {
|
||||
reducer: Reducer<LocationState>
|
||||
middleware: Middleware,
|
||||
thunk<S>(store: Store<S>): Promise<RouteThunk | void>,
|
||||
enhancer: GenericStoreEnhancer
|
||||
};
|
||||
|
||||
export function go(n: number): void;
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { connectRoutes, History, LocationState } from 'redux-first-router'
|
||||
import {
|
||||
createStore,
|
||||
applyMiddleware,
|
||||
Middleware,
|
||||
MiddlewareAPI,
|
||||
Store,
|
||||
Dispatch,
|
||||
compose,
|
||||
Action
|
||||
} from 'redux'
|
||||
|
||||
declare var console: any
|
||||
|
||||
declare var history: History
|
||||
|
||||
const routesMap = {
|
||||
HOME: '/'
|
||||
}
|
||||
|
||||
const {
|
||||
reducer,
|
||||
middleware,
|
||||
enhancer
|
||||
} = connectRoutes(history, routesMap)
|
||||
|
||||
const logger: Middleware = (store: MiddlewareAPI<LocationState>) => (next: Dispatch<LocationState>) => (action: Action) => {
|
||||
console.log(`Dispatching action ${action.type}...`)
|
||||
|
||||
next(action)
|
||||
}
|
||||
|
||||
const composedMiddleware = applyMiddleware(middleware, logger)
|
||||
|
||||
const store = createStore(reducer, compose(enhancer, composedMiddleware))
|
||||
|
||||
store.getState()
|
||||
|
||||
Reference in New Issue
Block a user