/* eslint-disable */ /* @flow strict */ /** * 1) Types give additional constraint on a language, recompose was written on the untyped language * as a consequence of this fact * for some recompose HOCs is near impossible to add correct typings. * 2) flow sometimes does not work as expected. * * So any help and suggestions will be very appreciated. * * ----------------------------------------------------------------------------------- * Type definition of recompose HOCs are splitted into 2 parts, * "HOCs with good flow support" - in most cases you can use them without big issues, * see `test_${hocName}.js` for the idea. * Some known issues: * see test_mapProps.js - inference work but type errors are not detected in hocs * * SUPPORTED HOCs: * defaultProps, mapProps, withProps, withStateHandlers, withHandlers, pure, * onlyUpdateForKeys, shouldUpdate, renderNothing, renderComponent, branch, withPropsOnChange, * onlyUpdateForPropTypes, toClass, withContext, getContext, * setStatic, setPropTypes, setDisplayName, * ----------------------------------------------------------------------------------- * "TODO (UNSUPPORTED) HOCs" - you need to provide type information * (no automatic type inference), voodoo dancing etc * see `test_voodoo.js` for the idea * * remember that: * flattenProp,renameProp, renameProps can easily be replaced with withProps * withReducer, withState -> use withStateHandlers instead * lifecycle -> you don't need recompose if you need a lifecycle, just use React class instead * mapPropsStream -> see test_mapPropsStream.js * ----------------------------------------------------------------------------------- * * utils: * getDisplayName, wrapDisplayName, shallowEqual, * isClassComponent, createSink, componentFromProp, * nest, hoistStatics, */ //------------------- // ----------------------------------------------------------------- // Private declarations // ----------------------------------------------------------------- declare type ExtractToVoid = ( v: (a: A, b: B, c: C) => R ) => (A, B, C) => void declare type ExtractStateHandlersCodomain = ( v: (state: State, props: Enhanced) => V ) => V declare type ExtractHandlersCodomain = ( v: (props: Enhanced) => V ) => V declare type UnaryFn = (a: A) => R // ----------------------------------------------------------------- // Public declarations // ----------------------------------------------------------------- export type Component = React$ComponentType export type HOC = UnaryFn, Component> declare export var compose: $Compose // --------------------------------------------------------------------------- // ----------------===<<>>===-------------------- // --------------------------------------------------------------------------- declare export function defaultProps( defProps: Default ): HOC<{ ...$Exact, ...Default }, Enhanced> declare export function mapProps( propsMapper: (ownerProps: Enhanced) => Base ): HOC declare export function withProps( propsMapper: ((ownerProps: Enhanced) => BaseAdd) | BaseAdd ): HOC<{ ...$Exact, ...BaseAdd }, Enhanced> declare export function withStateHandlers< State, Enhanced, StateHandlers: { [key: string]: ( state: State, props: Enhanced ) => (...payload: any[]) => $Shape, } >( initialState: ((props: Enhanced) => State) | State, stateUpdaters: StateHandlers ): HOC< { ...$Exact, ...$Exact, ...$ObjMap< $ObjMap, ExtractToVoid >, }, Enhanced > declare export function withHandlers< Enhanced, Handlers: | (( props: Enhanced ) => { [key: string]: (props: Enhanced) => Function, }) | { [key: string]: (props: Enhanced) => Function, } >( handlers: ((props: Enhanced) => Handlers) | Handlers ): HOC< { ...$Exact, ...$ObjMap, }, Enhanced > declare export function pure(a: Component): Component declare export function onlyUpdateForPropTypes(a: Component): Component declare export function onlyUpdateForKeys(Array<$Keys>): HOC declare export function shouldUpdate( (props: A, nextProps: A) => boolean ): HOC declare export function toClass(a: Component): Component declare export function withContext( childContextTypes: ContextPropTypes, getChildContext: (props: A) => ContextObj ): HOC declare export function getContext( contextTypes: CtxTypes ): HOC<{ ...$Exact, ...CtxTypes }, Enhanced> /** * It's wrong declaration but having that renderNothing and renderComponent are somehow useless * outside branch enhancer, we just give it an id type * so common way of using branch like * `branch(testFn, renderNothing | renderComponent(Comp))` will work as expected. * Tests are placed at test_branch. */ declare export function renderNothing(C: Component): Component declare export function renderComponent(a: Component): HOC /** * We make an assumtion that left and right have the same type if exists */ declare export function branch( testFn: (props: Enhanced) => boolean, // not a HOC because of inference problems, this works but HOC is not left: (Component) => Component, // I never use right part and it can be a problem with inference as should be same type as left right?: (Component) => Component ): HOC // test_statics declare export function setStatic(key: string, value: any): HOC declare export function setPropTypes(propTypes: Object): HOC declare export function setDisplayName(displayName: string): HOC declare export function withPropsOnChange( shouldMapOrKeys: | ((props: Enhanced, nextProps: Enhanced) => boolean) | Array<$Keys>, propsMapper: (ownerProps: Enhanced) => BaseAdd ): HOC<{ ...$Exact, ...BaseAdd }, Enhanced> // --------------------------------------------------------------------------- // ----------------===<<>>===------------------------ // --------------------------------------------------------------------------- // use withProps instead declare export function flattenProp( propName: $Keys ): HOC // use withProps instead declare export function renameProp( oldName: $Keys, newName: $Keys ): HOC // use withProps instead declare export function renameProps(nameMap: { [key: $Keys]: $Keys, }): HOC // use withStateHandlers instead declare export function withState( stateName: string, stateUpdaterName: string, initialState: T | ((props: Enhanced) => T) ): HOC // use withStateHandlers instead declare export function withReducer( stateName: string, dispatchName: string, reducer: (state: State, action: Action) => State, initialState: State ): HOC // lifecycle use React instead declare export function lifecycle(spec: Object): HOC // Help needed, as explicitly providing the type // errors not detected, see TODO at test_mapPropsStream.js declare export function mapPropsStream( (props$: any) => any ): HOC // --------------------------------------------------------------------------- // -----------------------------===<<>>===----------------------------- // --------------------------------------------------------------------------- declare export function getDisplayName(C: Component): string declare export function wrapDisplayName( C: Component, wrapperName: string ): string declare export function shallowEqual(objA: mixed, objB: mixed): boolean declare export function isClassComponent(value: any): boolean declare export function createSink( callback: (props: A) => void ): Component declare export function componentFromProp(propName: string): Component declare export function nest( ...Components: Array | string> ): Component declare export function hoistStatics>(hoc: H): H declare export function componentFromStream( (props$: any) => any ): T => React$Element declare export function createEventHandler(): { stream: any, handler: Function, } declare export function toRenderProps( hoc: HOC ): React$ComponentType<{| ...$Exact, children: (b: B) => React$Node, |}> declare export function fromRenderProps( RenderPropsComponent: Component<{ [RenderPropName]: (...props: Props) => React$Node, }>, propsMapper: ((...props: Props) => B), renderPropName?: RenderPropName ): HOC<{ ...$Exact, ...B }, E>