Merge upstream changes (#3)

This commit is contained in:
Zev Spitz
2017-09-10 08:44:56 +03:00
committed by GitHub
parent 3ec0a9d9ed
commit 4319f2ed28
5227 changed files with 151521 additions and 79509 deletions

View File

@@ -1,35 +1,50 @@
// Type definitions for react-redux 4.4.47
// Type definitions for react-redux 5.0.5
// Project: https://github.com/rackt/react-redux
// Definitions by: Qubo <https://github.com/tkqubo>, Sean Kelley <https://github.com/seansfkelley>, Thomas Hasner <https://github.com/thasner>
// Definitions by: Qubo <https://github.com/tkqubo>,
// Thomas Hasner <https://github.com/thasner>,
// Kenzie Togami <https://github.com/kenzierocks>,
// Curits Layne <https://github.com/clayne11>
// Frank Tan <https://github.com/tansongyang>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
// TypeScript Version: 2.4
import * as React from 'react';
import * as Redux from 'redux';
type ComponentClass<P> = React.ComponentClass<P>;
type StatelessComponent<P> = React.StatelessComponent<P>;
type Component<P> = ComponentClass<P> | StatelessComponent<P>;
type Component<P> = React.ComponentType<P>;
type ReactNode = React.ReactNode;
type Store<S> = Redux.Store<S>;
type Dispatch<S> = Redux.Dispatch<S>;
type ActionCreator<A> = Redux.ActionCreator<A>;
// Diff / Omit taken from https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-311923766
type Diff<T extends string, U extends string> = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];
type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;
export interface DispatchProp<S> {
dispatch: Dispatch<S>;
dispatch?: Dispatch<S>;
}
interface ComponentDecorator<TMergedProps, TOwnProps> {
(component: Component<TOwnProps & TMergedProps>): ComponentClass<TOwnProps>;
interface AdvancedComponentDecorator<TProps, TOwnProps> {
(component: Component<TProps>): ComponentClass<TOwnProps>;
}
interface ComponentDecoratorInfer<TMergedProps> {
<T>(component: Component<T & TMergedProps>): ComponentClass<T>;
// Injects props and removes them from the prop requirements.
// Will not pass through the injected props if they are passed in during
// render. Also adds new prop requirements from TNeedsProps.
export interface InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> {
<P extends TInjectedProps>(
component: Component<P>
): ComponentClass<Omit<P, keyof TInjectedProps> & TNeedsProps>
}
interface ComponentMergeDecorator<TMergedProps, TOwnProps> {
(component: Component<TMergedProps>): ComponentClass<TOwnProps>;
}
// Injects props and removes them from the prop requirements.
// Will not pass through the injected props if they are passed in during
// render.
export type InferableComponentEnhancer<TInjectedProps> =
InferableComponentEnhancerWithProps<TInjectedProps, {}>
/**
* Connects a React component to a Redux store.
@@ -50,97 +65,93 @@ interface ComponentMergeDecorator<TMergedProps, TOwnProps> {
* @param mergeProps
* @param options
*/
export declare function connect(): ComponentDecoratorInfer<DispatchProp<any>>;
export declare function connect(): InferableComponentEnhancer<DispatchProp<any>>;
export declare function connect<TStateProps, no_dispatch, TOwnProps>(
export declare function connect<TStateProps = {}, no_dispatch = {}, TOwnProps = {}>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps>
): ComponentDecorator<TStateProps, TOwnProps>;
): InferableComponentEnhancerWithProps<TStateProps & DispatchProp<any>, TOwnProps>;
export declare function connect<no_state, TDispatchProps, TOwnProps>(
export declare function connect<no_state = {}, TDispatchProps = {}, TOwnProps = {}>(
mapStateToProps: null | undefined,
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>
): ComponentDecorator<TDispatchProps, TOwnProps>;
): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>;
export declare function connect<TStateProps, TDispatchProps, TOwnProps>(
export declare function connect<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps>,
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>
): ComponentDecorator<TStateProps & TDispatchProps, TOwnProps>;
): InferableComponentEnhancerWithProps<TStateProps & TDispatchProps, TOwnProps>;
export declare function connect<TStateProps, no_dispatch, TOwnProps, TMergedProps>(
export declare function connect<TStateProps = {}, no_dispatch = {}, TOwnProps = {}, TMergedProps = {}>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps>,
mapDispatchToProps: null | undefined,
mergeProps: MergeProps<TStateProps, undefined, TOwnProps, TMergedProps>,
): ComponentMergeDecorator<TMergedProps, TOwnProps>;
): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>;
export declare function connect<no_state, TDispatchProps, TOwnProps, TMergedProps>(
export declare function connect<no_state = {}, TDispatchProps = {}, TOwnProps = {}, TMergedProps = {}>(
mapStateToProps: null | undefined,
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
mergeProps: MergeProps<undefined, TDispatchProps, TOwnProps, TMergedProps>,
): ComponentMergeDecorator<TMergedProps, TOwnProps>;
): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>;
export declare function connect<no_state, no_dispatch, TOwnProps, TMergedProps>(
export declare function connect<no_state = {}, no_dispatch = {}, TOwnProps = {}, TMergedProps = {}>(
mapStateToProps: null | undefined,
mapDispatchToProps: null | undefined,
mergeProps: MergeProps<undefined, undefined, TOwnProps, TMergedProps>,
): ComponentMergeDecorator<TMergedProps, TOwnProps>;
): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>;
export declare function connect<TStateProps, TDispatchProps, TOwnProps, TMergedProps>(
export declare function connect<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, TMergedProps = {}>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps>,
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
mergeProps: MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps>,
): ComponentMergeDecorator<TMergedProps, TOwnProps>;
): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>;
export declare function connect<TStateProps, no_dispatch, TOwnProps>(
export declare function connect<TStateProps = {}, no_dispatch = {}, TOwnProps = {}>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps>,
mapDispatchToProps: null | undefined,
mergeProps: null | undefined,
options: Options
): ComponentDecorator<DispatchProp<any> & TStateProps, TOwnProps>;
options: Options<TStateProps, TOwnProps>
): InferableComponentEnhancerWithProps<DispatchProp<any> & TStateProps, TOwnProps>;
export declare function connect<no_state, TDispatchProps, TOwnProps>(
export declare function connect<no_state = {}, TDispatchProps = {}, TOwnProps = {}>(
mapStateToProps: null | undefined,
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
mergeProps: null | undefined,
options: Options
): ComponentDecorator<TDispatchProps, TOwnProps>;
options: Options<no_state, TOwnProps>
): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>;
export declare function connect<TStateProps, TDispatchProps, TOwnProps>(
export declare function connect<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps>,
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
mergeProps: null | undefined,
options: Options
): ComponentDecorator<TStateProps & TDispatchProps, TOwnProps>;
options: Options<TStateProps, TOwnProps>
): InferableComponentEnhancerWithProps<TStateProps & TDispatchProps, TOwnProps>;
export declare function connect<TStateProps, TDispatchProps, TOwnProps, TMergedProps>(
export declare function connect<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, TMergedProps = {}>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps>,
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
mergeProps: MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps>,
options: Options
): ComponentMergeDecorator<TMergedProps, TOwnProps>;
options: Options<TStateProps, TOwnProps, TMergedProps>
): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>;
interface MapStateToProps<TStateProps, TOwnProps> {
(state: any, ownProps?: TOwnProps): TStateProps;
(state: any, ownProps: TOwnProps): TStateProps;
}
interface MapStateToPropsFactory<TStateProps, TOwnProps> {
(initialState: any, ownProps?: TOwnProps): MapStateToProps<TStateProps, TOwnProps>;
(initialState: any, ownProps: TOwnProps): MapStateToProps<TStateProps, TOwnProps>;
}
type MapStateToPropsParam<TStateProps, TOwnProps> = MapStateToProps<TStateProps, TOwnProps> | MapStateToPropsFactory<TStateProps, TOwnProps>;
interface MapDispatchToPropsFunction<TDispatchProps, TOwnProps> {
(dispatch: Dispatch<any>, ownProps?: TOwnProps): TDispatchProps;
}
interface MapDispatchToPropsObject {
[name: string]: ActionCreator<any>;
(dispatch: Dispatch<any>, ownProps: TOwnProps): TDispatchProps;
}
type MapDispatchToProps<TDispatchProps, TOwnProps> =
MapDispatchToPropsFunction<TDispatchProps, TOwnProps> | MapDispatchToPropsObject;
MapDispatchToPropsFunction<TDispatchProps, TOwnProps> | TDispatchProps;
interface MapDispatchToPropsFactory<TDispatchProps, TOwnProps> {
(dispatch: Dispatch<any>, ownProps?: TOwnProps): MapDispatchToProps<TDispatchProps, TOwnProps>;
(dispatch: Dispatch<any>, ownProps: TOwnProps): MapDispatchToProps<TDispatchProps, TOwnProps>;
}
type MapDispatchToPropsParam<TDispatchProps, TOwnProps> = MapDispatchToProps<TDispatchProps, TOwnProps> | MapDispatchToPropsFactory<TDispatchProps, TOwnProps>;
@@ -149,7 +160,7 @@ interface MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps> {
(stateProps: TStateProps, dispatchProps: TDispatchProps, ownProps: TOwnProps): TMergedProps;
}
interface Options {
interface Options<TStateProps = {}, TOwnProps = {}, TMergedProps = {}> extends ConnectOptions {
/**
* If true, implements shouldComponentUpdate and shallowly compares the result of mergeProps,
* preventing unnecessary updates, assuming that the component is a “pure” component
@@ -158,11 +169,106 @@ interface Options {
* @default true
*/
pure?: boolean;
/**
* If true, stores a ref to the wrapped component instance and makes it available via
* getWrappedInstance() method. Defaults to false.
* When pure, compares incoming store state to its previous value.
* @default strictEqual
*/
withRef?: boolean;
areStatesEqual?: (nextState: any, prevState: any) => boolean;
/**
* When pure, compares incoming props to its previous value.
* @default shallowEqual
*/
areOwnPropsEqual?: (nextOwnProps: TOwnProps, prevOwnProps: TOwnProps) => boolean;
/**
* When pure, compares the result of mapStateToProps to its previous value.
* @default shallowEqual
*/
areStatePropsEqual?: (nextStateProps: TStateProps, prevStateProps: TStateProps) => boolean;
/**
* When pure, compares the result of mergeProps to its previous value.
* @default shallowEqual
*/
areMergedPropsEqual?: (nextMergedProps: TMergedProps, prevMergedProps: TMergedProps) => boolean;
}
/**
* Connects a React component to a Redux store. It is the base for {@link connect} but is less opinionated about
* how to combine <code>state</code>, <code>props</code>, and <code>dispatch</code> into your final props. It makes no
* assumptions about defaults or memoization of results, leaving those responsibilities to the caller.It does not
* modify the component class passed to it; instead, it returns a new, connected component class for you to use.
*
* @param selectorFactory The selector factory. See {@type SelectorFactory} for details.
* @param connectOptions If specified, further customizes the behavior of the connector. Additionally, any extra
* options will be passed through to your <code>selectorFactory</code> in the <code>factoryOptions</code> argument.
*/
export declare function connectAdvanced<S, TProps, TOwnProps, TFactoryOptions = {}>(
selectorFactory: SelectorFactory<S, TProps, TOwnProps, TFactoryOptions>,
connectOptions?: ConnectOptions & TFactoryOptions
): AdvancedComponentDecorator<TProps, TOwnProps>;
/**
* Initializes a selector function (during each instance's constructor). That selector function is called any time the
* connector component needs to compute new props, as a result of a store state change or receiving new props. The
* result of <code>selector</code> is expected to be a plain object, which is passed as the props to the wrapped
* component. If a consecutive call to <code>selector</code> returns the same object (<code>===</code>) as its previous
* call, the component will not be re-rendered. It's the responsibility of <code>selector</code> to return that
* previous object when appropriate.
*/
export interface SelectorFactory<S, TProps, TOwnProps, TFactoryOptions> {
(dispatch: Dispatch<S>, factoryOptions: TFactoryOptions): Selector<S, TProps, TOwnProps>
}
export interface Selector<S, TProps, TOwnProps> {
(state: S, ownProps: TOwnProps): TProps
}
export interface ConnectOptions {
/**
* Computes the connector component's displayName property relative to that of the wrapped component. Usually
* overridden by wrapper functions.
*
* @default name => 'ConnectAdvanced('+name+')'
* @param componentName
*/
getDisplayName?: (componentName: string) => string
/**
* Shown in error messages. Usually overridden by wrapper functions.
*
* @default 'connectAdvanced'
*/
methodName?: string
/**
* If defined, a property named this value will be added to the props passed to the wrapped component. Its value
* will be the number of times the component has been rendered, which can be useful for tracking down unnecessary
* re-renders.
*
* @default undefined
*/
renderCountProp?: string
/**
* Controls whether the connector component subscribes to redux store state changes. If set to false, it will only
* re-render on <code>componentWillReceiveProps</code>.
*
* @default true
*/
shouldHandleStateChanges?: boolean
/**
* The key of props/context to get the store. You probably only need this if you are in the inadvisable position of
* having multiple stores.
*
* @default 'store'
*/
storeKey?: string
/**
* If true, stores a ref to the wrapped component instance and makes it available via getWrappedInstance() method.
*
* @default false
*/
withRef?: boolean
}
export interface ProviderProps {

View File

@@ -1,5 +1,6 @@
{
"dependencies": {
"redux": "^3.6.0"
}
}
"private": true,
"dependencies": {
"redux": "^3.6.0"
}
}

View File

@@ -1,7 +1,7 @@
import { Component, ReactElement } from 'react';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Store, Dispatch, bindActionCreators } from 'redux';
import { Store, Dispatch, ActionCreator, bindActionCreators } from 'redux';
import { connect, Provider, DispatchProp, MapStateToProps } from 'react-redux';
import objectAssign = require('object-assign');
@@ -57,21 +57,21 @@ interface ICounterDispatchProps {
onIncrement: () => void
}
// with higher order functions
connect<ICounterStateProps, ICounterDispatchProps, {}>(
connect<ICounterStateProps, ICounterDispatchProps>(
() => mapStateToProps,
() => mapDispatchToProps
)(Counter);
// with higher order functions using parameters
connect<ICounterStateProps, ICounterDispatchProps, {}>(
(initialState: CounterState, ownProps: {}) => mapStateToProps,
(dispatch: Dispatch<CounterState>, ownProps: {}) => mapDispatchToProps
connect<ICounterStateProps, ICounterDispatchProps>(
(initialState: CounterState, ownProps) => mapStateToProps,
(dispatch: Dispatch<CounterState>, ownProps) => mapDispatchToProps
)(Counter);
// only first argument
connect<ICounterStateProps, {}, {}>(
connect<ICounterStateProps>(
() => mapStateToProps
)(Counter);
// wrap only one argument
connect<ICounterStateProps, ICounterDispatchProps, {}>(
connect<ICounterStateProps, ICounterDispatchProps>(
mapStateToProps,
() => mapDispatchToProps
)(Counter);
@@ -294,12 +294,14 @@ class NonComponent {}
//connect()(NonComponent);
// stateless functions
interface HelloMessageProps { name: string; }
function HelloMessage(props: HelloMessageProps) {
interface HelloMessageProps {
dispatch: Dispatch<any>
name: string;
}
const HelloMessage: React.StatelessComponent<HelloMessageProps> = (props) => {
return <div>Hello {props.name}</div>;
}
let ConnectedHelloMessage = connect()(HelloMessage);
ReactDOM.render(<HelloMessage name="Sebastian" />, document.getElementById('content'));
ReactDOM.render(<ConnectedHelloMessage name="Sebastian" />, document.getElementById('content'));
// stateless functions that uses mapStateToProps and mapDispatchToProps
@@ -494,3 +496,76 @@ namespace Issue15463 {
<Spinner />
}
namespace RemoveInjectedAndPassOnRest {
interface TProps {
showGlobalSpinner: boolean;
foo: string;
}
class SpinnerClass extends React.Component<TProps & DispatchProp<any>, {}> {
render() {
return (<div />);
}
}
export const Spinner = connect((state: any) => {
return { showGlobalSpinner: true };
})(SpinnerClass);
<Spinner foo='bar' />
}
namespace TestControlledComponentWithoutDispatchProp {
interface MyState {
count: number;
}
interface MyProps {
label: string;
// `dispatch` is optional, but setting it to anything
// other than Dispatch<T> will cause an error
//
// dispatch: Dispatch<any>; // OK
// dispatch: number; // ERROR
}
function mapStateToProps(state: MyState) {
return {
label: `The count is ${state.count}`,
}
}
class MyComponent extends React.Component<MyProps> {
render() {
return <span>{this.props.label}</span>;
}
}
const MyFuncComponent = (props: MyProps) => (
<span>{props.label}</span>
);
const MyControlledComponent = connect(mapStateToProps)(MyComponent);
const MyControlledFuncComponent = connect(mapStateToProps)(MyFuncComponent);
}
namespace TestDispatchToPropsAsObject {
const onClick: ActionCreator<{}> = null;
const mapStateToProps = (state: any) => {
return {
title: state.app.title as string,
};
};
const dispatchToProps = {
onClick,
};
type Props = { title: string; } & typeof dispatchToProps;
const HeaderComponent: React.StatelessComponent<Props> = (props) => {
return <h1>{props.title}</h1>;
}
const Header = connect(mapStateToProps, dispatchToProps)(HeaderComponent);
<Header />
}