import * as React from "react"; import { promised } from "../utilities/functions"; /** * @module * * ## Rejected updates * * Updates can be rejected. A rejected update indicates to the * ControlledUpdates component that the user component was in * an invalid state to process the update. These rejected updates * are stored and **must be explicitly flushed**. */ declare type identifiedPromised = [promised, string?]; export interface IUpdateControllable { /** * Block updates until `allowUpdates` is called */ preventUpdates(): void; /** * Allow updates until `blockUpdates` is called */ allowUpdates(): void; /** * Add an update to be run when updates are allowed. If updates * are allowed when the update is pushed, it will be run. */ pushUpdate(update: promised, id?: string): void; /** * Explicitly run an update. */ flushUpdate?(id: string, flushed?: () => void): void; /** * Accept a reject update(s) */ acceptUpdate?(id: string): void; } export interface IControlledUpdatesState
{ /** * This flag is toggled by `preventUpdates` and `allowUpdates`. If this * is false, any updates will be blocked. */ canUpdate: boolean; /** * This flag is used internally to notate whether the component has begun processing updates. */ isUpdating: boolean; /** * This flag is used internally to notate whether the component has begun flushing an update. */ isFlushing: boolean; /** * The list of updates */ updates: (identifiedPromised)[]; /** * The execution of an update can be rejected. When this happens, the update is pushed * onto the `rejectedUpdate` stack. `rejectedUpdates` are only executed when updates would * have normally been processed. Rejected updates are non-replacing. This is distinct from * regular updates. In the future, this will be cleaned up to be some sort of configurable flag * on an update type. */ rejectedUpdates: (identifiedPromised)[]; /** * The props that need to be passed down to the component. */ componentProps?: P; /** * The props that have been passed down to the component. If * this and `componentProps` are not the same then we know we * have new props to pass down to the component */ prevComponentProps?: P; } export declare const withControlledUpdates:
(Component: React.ComponentType
) => { new (props: Readonly
): { state: IControlledUpdatesState
; shouldComponentUpdate(nextProps: P, nextState: IControlledUpdatesState
): boolean; componentDidUpdate(prevProps: P, prevState: IControlledUpdatesState
): void;
render: () => JSX.Element;
preventUpdates: () => void;
allowUpdates: () => void;
pushUpdate: (update: promised, id?: string) => void;
rejectUpdate: (update: [promised, string?]) => void;
canFlush: (id: string) => boolean;
flushUpdate: (id: string, flushed?: () => void) => void;
/**
* Accept and run rejected update(s)
*/
acceptUpdate: (id: string) => void;
enqueueUpdate: (update: promised, id?: string) => Promise<{}>;
context: any;
setState | ((prevState: Readonly ) => IControlledUpdatesState | Pick & Readonly<{
children?: React.ReactNode;
}>;
refs: {
[key: string]: React.ReactInstance;
};
componentDidMount?(): void;
componentWillUnmount?(): void;
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
getSnapshotBeforeUpdate?(prevProps: Readonly , prevState: Readonly , nextContext: any): void;
UNSAFE_componentWillReceiveProps?(nextProps: Readonly , nextContext: any): void;
componentWillUpdate?(nextProps: Readonly , nextState: Readonly , nextState: Readonly ;
shouldComponentUpdate(nextProps: P, nextState: IControlledUpdatesState ): boolean;
componentDidUpdate(prevProps: P, prevState: IControlledUpdatesState ): void;
render: () => JSX.Element;
preventUpdates: () => void;
allowUpdates: () => void;
pushUpdate: (update: promised, id?: string) => void;
rejectUpdate: (update: [promised, string?]) => void;
canFlush: (id: string) => boolean;
flushUpdate: (id: string, flushed?: () => void) => void;
/**
* Accept and run rejected update(s)
*/
acceptUpdate: (id: string) => void;
enqueueUpdate: (update: promised, id?: string) => Promise<{}>;
context: any;
setState | ((prevState: Readonly ) => IControlledUpdatesState | Pick & Readonly<{
children?: React.ReactNode;
}>;
refs: {
[key: string]: React.ReactInstance;
};
componentDidMount?(): void;
componentWillUnmount?(): void;
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
getSnapshotBeforeUpdate?(prevProps: Readonly , prevState: Readonly , nextContext: any): void;
UNSAFE_componentWillReceiveProps?(nextProps: Readonly , nextContext: any): void;
componentWillUpdate?(nextProps: Readonly , nextState: Readonly , nextState: Readonly ): {
componentProps: P;
prevComponentProps: P;
};
contextType?: React.Context