import * as React from 'react';
/**
* Simplified React.SFC
*/
export declare type DecoratedSFC
= (props: P & {
children?: React.ReactNode;
}, context?: any) => React.ReactElement | null;
/**
* Simplified React.ComponentClass
*/
export interface DecoratedComponentClass {
new (props: P, context?: any): React.Component;
}
/**
* Simplified component (class or stateless)
* We use this to help generics with the type (the class is technically still a function
* + they have common properties - like propTypes, defaultProps, etc. -
* so Typescript has a hard time distinguish between them)
* Also it helps us to get less clutter in the error messages.
*/
export declare type DecoratedComponent = DecoratedSFC
| DecoratedComponentClass
;
export interface LifecycleMethodsThis {
props: TProps;
}
export interface LifecycleMethods {
componentWillMount?: (this: LifecycleMethodsThis) => void;
componentDidMount?: (this: LifecycleMethodsThis) => void;
componentWillReceiveProps?: (this: LifecycleMethodsThis, nextProps: TProps) => void;
shouldComponentUpdate?: (this: LifecycleMethodsThis, nextProps: TProps, nextState: any) => boolean;
componentWillUpdate?: (this: LifecycleMethodsThis, nextProps: TProps, nextState: any) => void;
componentDidUpdate?: (this: LifecycleMethodsThis, prevProps: TProps, prevState: any) => void;
componentWillUnmount?: (this: LifecycleMethodsThis) => void;
componentDidCatch?: (this: LifecycleMethodsThis, error: Error, errorInfo: React.ErrorInfo) => void;
}
/**
* Fluent interface to allow composition of multiple higher-order components into single decorator.
* This is an Typescript enabled replacement for compose()
*/
export interface ComponentDecoratorBuilder {
/**
* Allows to apply custom decorators.
*/
withDecorator(t: GenericComponentDecorator | ComponentDecorator): ComponentDecoratorBuilder> & TDR, TOmittedProps | TDO, TStatic & TDS>;
/**
* Allows apply decorators from another decorator builder
*/
append, TResultingProps2, TOmittedProps2 extends string, TStatic2 extends {}>(decoratorBuilder: ComponentDecoratorBuilder): ComponentDecoratorBuilder> & TResultingProps2, TOmittedProps | TOmittedProps2, TStatic & TStatic2>;
/**
* Allows to pass additional props by calculating them from already passed props.
*
* Further info: https://neoziro.github.io/recompact/#withpropspropsmapper
*/
withProps(createProps: (props: TResultingProps) => T3): ComponentDecoratorBuilder;
/**
* Allows to pass additional props.
*
* Further info: https://neoziro.github.io/recompact/#withpropspropsmapper
*/
withProps(props: T3): ComponentDecoratorBuilder;
/**
* Similar to withProps(). Allows to create additional props if any of specified existing props changed.
*
* Further info: https://neoziro.github.io/recompact/#withpropsonchangeshouldmaporkeys-createprops
*/
withPropsOnChange(propNames: Array, createProps: (props: TResultingProps) => T3): ComponentDecoratorBuilder;
/**
* Similar to withProps(). Allows to create additional props if given callback decides that it should
* (based on current and previous props).
*
* Further info: https://neoziro.github.io/recompact/#withpropsonchangeshouldmaporkeys-createprops
*/
withPropsOnChange(shouldCreateProps: (prevProps: TResultingProps, nextProps: TResultingProps) => boolean, createProps: (props: TResultingProps) => T3): ComponentDecoratorBuilder;
/**
* Sets defaultProps on the resulting component while updating the type definition to see given props as always defined.
*/
withDefaultProps>(defaultProps: T3): ComponentDecoratorBuilder> & {
[k in keyof T3]: k extends keyof TResultingProps ? Exclude : never;
}, TOmittedProps, TStatic>;
/**
* Gets value from context and passes it as a prop.
*/
withPropFromContext(propName: string, createProps: (propValue: any, props: TResultingProps) => TMappedProps): ComponentDecoratorBuilder;
/**
* Gets value from context and passes it as a prop.
*/
withPropFromContext(propName: React.Context, createProps: (propValue: T, props: TResultingProps) => TMappedProps): ComponentDecoratorBuilder;
/**
* Prevents any given previously set properties to be passed to base component.
*
* Further info: https://neoziro.github.io/recompact/#omitpropspaths
*/
omitProps(propName: T3 | T3[]): ComponentDecoratorBuilder>, TOmittedProps | Extract, TStatic>;
/**
* Creates two additional props to the base component: a state value, and a function to update that state value.
* The initial value is created from props by given callback.
* The state value can be derived from props on each update by given callback as the fourth parameter
*
* Further info: https://neoziro.github.io/recompact/#withstatestatename-stateupdatername-initialstate
*/
withState(propName: T3, setterPropName: T4, initiaValueFromProps: (props: TResultingProps) => T5, derivedStateFromProps?: (props: TResultingProps, state: T5) => Partial | null): ComponentDecoratorBuilder T5), callback?: () => void) => T5;
}, TOmittedProps, TStatic>;
/**
* Creates two additional props to the base component: a state value, and a function to update that state value.
* The state value can be derived from props on each update by given callback as the fourth parameter
*
* Further info: https://neoziro.github.io/recompact/#withstatestatename-stateupdatername-initialstate
*/
withState(propName: T3, setterPropName: T4, initialValue: T5, derivedStateFromProps?: (props: TResultingProps, state: T5) => T5 | null): ComponentDecoratorBuilder T5), callback?: () => void) => T5;
}, TOmittedProps, TStatic>;
/**
* Creates handler which is passed to component as a prop. It is defined as a higher-order function.
* This allows the handler to access the current props via closure, without needing to change its signature.
* Handlers are passed to the base component as immutable props, whose identities are preserved across renders.
* This avoids a common pitfall where functional components create handlers inside the body of the function,
* which results in a new handler on every render and breaks downstream shouldComponentUpdate()
* optimizations that rely on prop equality.
*
* Further info: https://neoziro.github.io/recompact/#withhandlershandlerfactories
*/
withHandler(handlerName: T3, handler: (props: TResultingProps) => T4): ComponentDecoratorBuilder;
/**
* Takes an object map of handler creators or a factory function. They are defined as higher-order functions.
* This allows the handler to access the current props via closure, without needing to change its signature.
* Handlers are passed to the base component as immutable props, whose identities are preserved across renders.
* This avoids a common pitfall where functional components create handlers inside the body of the function,
* which results in a new handler on every render and breaks downstream shouldComponentUpdate()
* optimizations that rely on prop equality.
*/
withHandlers any;
}>(handlers: THandlers | ((initialProps: TResultingProps) => THandlers)): ComponentDecoratorBuilder;
}, TOmittedProps, TStatic>;
/**
* Prevents the component from updating unless a prop corresponding to one of the given keys
* has updated. Uses shallowEqual() to test for changes.
* This is a much better optimization than the popular approach of using PureRenderMixin, shouldPureComponentUpdate(), or pure() helper,
* because those tools compare every prop, whereas onlyUpdateForKeys() only cares about the props that you specify.
*/
onlyUpdateForProps(propNames: Array): ComponentDecoratorBuilder;
/**
* Higher-order component version of shouldComponentUpdate().
* The test function accepts both the current props and the next props.
*/
shouldUpdate(shouldUpdate: (prevProps: TResultingProps, nextProps: TResultingProps) => boolean): ComponentDecoratorBuilder;
/**
* Allows to register component lifecycle methods like `componentDidMount` etc.
*/
withLifecycle(lifecycleMethods: LifecycleMethods): ComponentDecoratorBuilder;
/**
* Assigns to the displayName property on the base component.
*/
withDisplayName(displayName: string): ComponentDecoratorBuilder;
/**
* Assigns given static properties to the resulting (top-most) component.
*/
withStatic(props: TS): ComponentDecoratorBuilder;
/**
* Ensures component won't get rerendered unless identity of some prop changes.
*/
pure(): ComponentDecoratorBuilder;
/** Call this to create component decorator. */
build(): BuiltComponentDecorator;
}
export declare type DecoratedComponentProps = Pick> & TResultingProps;
export declare type Simplify = Pick;
export declare abstract class AbstractComponentDecorator {
private __initialProps;
private __omittedProps;
private __resultingProps;
private __staticProps;
}
export interface ComponentDecorator extends AbstractComponentDecorator, GenericComponentDecorator {
}
export interface GenericComponentDecorator {
(component: DecoratedComponent>): DecoratedComponent;
}
export interface BuiltComponentDecorator extends AbstractComponentDecorator, TOmittedProps, TStatic> {
(component: DecoratedComponent): React.ComponentClass & TStatic;
}