Created
September 14, 2015 07:38
-
-
Save s-panferov/b5c681023ca457c505b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module "react-redux" { | |
import React from "react"; | |
import * as redux from "redux"; | |
interface ProviderProps { | |
store: redux.Store<any, any>; | |
} | |
interface ProviderState { | |
store: redux.Store<any, any>; | |
} | |
class Provider extends React.Component<ProviderProps, ProviderState> {} | |
interface ConnectorProps { | |
children: Function; | |
select: Function; | |
} | |
class Connector extends React.Component<ConnectorProps, any> {} | |
interface ConnectorOptions { | |
/** | |
* If true, implements shouldComponentUpdate and shallowly compares | |
* the result of mergeProps, preventing unnecessary updates, | |
* assuming that the component is a “pure” component and does not rely | |
* on any input or state other than its props and the selected | |
* Redux store’s state. Defaults to true. | |
*/ | |
pure: boolean; | |
} | |
interface DispatchProps<A> { | |
dispatch?: redux.Dispatch<A>; | |
} | |
interface MapStateToProps<P, State, StateProps> { | |
(state: State, ownProps: P): StateProps; | |
} | |
interface MapDispatchToProps<P, Dispatch> { | |
(state: Dispatch, ownProps: P): any; | |
} | |
interface MergeProps<P, StateProps, DispatchProps> { | |
(stateProps: StateProps, dispatchProps: DispatchProps, ownProps: P): P; | |
} | |
interface Connect<State, Action, Dispatch> { | |
<P, StateProps, DispatchProps>( | |
/** | |
* If specified, the component will subscribe to Redux store updates. | |
* Any time it updates, mapStateToProps will be called. | |
* Its result must be a plain object, and it will be merged into the component’s props. | |
* If you omit it, the component will not be subscribed to the Redux store. | |
* If ownProps is specified as a second argument, then mapStateToProps will | |
* be re-invoked whenever the component receives new props. | |
*/ | |
mapStateToProps?: MapStateToProps<P, State, StateProps>, | |
/** | |
* If an object is passed, each function inside it will be assumed | |
* to be a Redux action creator. An object with the same function names, | |
* but bound to a Redux store, will be merged into the component’s props. | |
* If a function is passed, it will be given dispatch. It’s up to you | |
* to return an object that somehow uses dispatch to bind action creators in your own way. | |
* (Tip: you may use the bindActionCreators() helper from Redux.) | |
* If you omit it, the default implementation just injects dispatch into your | |
* component’s props. If ownProps is specified as a second argument, | |
* then mapDispatchToProps will be re-invoked whenever the component receives new props. | |
*/ | |
mapDispatchToProps?: redux.ActionCreators<State, Action> | MapDispatchToProps<P, Dispatch>, | |
/** | |
* If specified, it is passed the result of mapStateToProps(), mapDispatchToProps(), and the parent props. | |
* The plain object you return from it will be passed as props to the wrapped component. | |
* You may specify this function to select a slice of the state based on props, | |
* or to bind action creators to a particular variable from props. | |
* If you omit it, Object.assign({}, ownProps, stateProps, dispatchProps) is used by default. | |
*/ | |
mergeProps?: MergeProps<P, StateProps, DispatchProps>, | |
/** | |
* If specified, further customizes the behavior of the connector. | |
*/ | |
options?: ConnectorOptions | |
) | |
} | |
let connect: Connect<any, any, redux.Dispatch<any>>; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module "redux" { | |
interface Action<T> { | |
type: T; | |
} | |
interface ActionFunction<S, A> { | |
(dispatch: Dispatch<A>, getState: () => S): void; | |
} | |
interface ActionCreator<S, A> { | |
(...args: any[]): A | ActionFunction<S, A>; | |
} | |
interface ActionCreators<S, A> { | |
[key: string]: ActionCreator<S, A>; | |
} | |
interface Reducer<S, A> { | |
(state: S, action: A): S; | |
} | |
interface Reducers<S, A> { | |
[key: string]: Reducer<S, A>; | |
} | |
interface Dispatch<A> { | |
(action: A): A; | |
} | |
interface StoreMethods<S, A> { | |
dispatch: Dispatch<A>; | |
getState(): S; | |
} | |
interface MiddlewareArg<S, A> { | |
dispatch: Dispatch<A>; | |
getState: () => S; | |
} | |
interface Middleware<S, A> { | |
// TODO @spanferov Write proper types | |
(obj: MiddlewareArg<S, A>): Function; | |
} | |
interface Store<S, A> { | |
dispatch: Dispatch<A>; | |
getReducer(): Reducer<S, A>; | |
replaceReducer(nextReducer: Reducer<S, A>): void; | |
getState(): S; | |
// TODO @spanferov Write proper types | |
subscribe(listener: Function): Function; | |
} | |
interface StoreCreator<S, A> { | |
(reducer: Reducer<S, A>, initialState?: S): Store<S, A>; | |
} | |
export function createStore<S, A>(reducer: Reducer<S, A>, initialState?: S): Store<S, A>; | |
export function bindActionCreators<S, A>(actionCreators: ActionCreators<S, A>, dispatch: Dispatch<A>): ActionCreators<S, A>; | |
export function combineReducers<S, A>(reducers: Reducers<S, A>): Reducer<S, A>; | |
export function applyMiddleware<S, A>(...middleware: Middleware<S, A>[]): (createStore: StoreCreator<S, A>) => StoreCreator<S,A>; | |
export function compose(...functions: Function[]): Function; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
Action as ReduxAction, | |
createStore as reduxCreateStore, | |
applyMiddleware as reduxApplyMiddleware, | |
StoreCreator, | |
Store as ReduxStore, | |
Dispatch as ReduxDispatch | |
} from 'redux'; | |
import { | |
Provider, | |
Connect, | |
connect as reduxConnect, | |
DispatchProps as ReduxDispatchProps | |
} from 'react-redux'; | |
import { ActionType } from './actions'; | |
import { AppState } from './state'; | |
import * as actions from './actions'; | |
export { | |
Provider, actions | |
}; | |
export type Action = ReduxAction<ActionType>; | |
export type State = AppState; | |
export type Store = ReduxStore<State, Action>; | |
export type Dispatch = ReduxDispatch<Action>; | |
export type ActionCreators = typeof actions; | |
export type DispatchProps = ReduxDispatchProps<Action>; | |
export let createStore: StoreCreator<State, Action> = reduxCreateStore; | |
export let connect: Connect<State, Action, Dispatch> = reduxConnect; | |
export let applyMiddleware = reduxApplyMiddleware |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment