Skip to content

Instantly share code, notes, and snippets.

@stepancar
Created March 17, 2016 12:04
Show Gist options
  • Save stepancar/d671ac7f76da1c0a68bd to your computer and use it in GitHub Desktop.
Save stepancar/d671ac7f76da1c0a68bd to your computer and use it in GitHub Desktop.
import { Component } from 'react';
import { Store, Dispatch, ActionCreator } from 'redux';
import { connect as reduxConnect} from 'react-redux';
export class ElementClass<P, S> extends Component<P, S> { }
export interface ClassDecorator<P, S, T> {
<P, S, T extends constructorof<ElementClass<P, S>>>(component: T): T
}
interface MapStateToProps<P> {
(state: any, ownProps?: any): P;
}
interface MapDispatchToPropsFunction {
(dispatch: Dispatch, ownProps?: any): any;
}
interface MapDispatchToPropsObject {
[name: string]: ActionCreator;
}
interface MergeProps {
(stateProps: any, dispatchProps: any, ownProps: any): any;
}
interface Options {
/**
* 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.
* @default true
*/
pure: boolean;
}
interface constructorof<T> {
new (...args: Array<any>): T;
}
export function connect<P, T extends constructorof<ElementClass<P, any>>>(componentType: T, mapStateToProps?: MapStateToProps<P>,
mapDispatchToProps?: MapDispatchToPropsFunction | MapDispatchToPropsObject,
mergeProps?: MergeProps,
options?: Options): T {
return reduxConnect(mapStateToProps, mapDispatchToProps, mergeProps, options)(componentType);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment