@ima/core
Version:
IMA.js framework for isomorphic javascript application
60 lines • 1.95 kB
TypeScript
export type PageState = {
[key: string]: any;
};
/**
* Manager of the current page state and state history.
*/
export declare abstract class PageStateManager<S extends PageState = {}> {
onChange?: (newState: S) => void;
/**
* Clears the state history.
*/
clear(): void;
/**
* Sets a new page state by applying the provided patch to the current
* state.
*
* @param statePatch The patch of the current state.
*/
setState<K extends keyof S>(patchState: Pick<S, K> | S | null): void;
/**
* Returns the current page state.
*
* @return The current page state.
*/
getState(): S;
/**
* Returns the recorded history of page states. The states will be
* chronologically sorted from the oldest to the newest.
*
* Note that the implementation may limit the size of the recorded history,
* therefore the complete history may not be available.
*
* @return The recorded history of page states.
*/
getAllStates(): S[];
/**
* Returns queueing state patches off the main state from the begin of transaction.
*
* @return State patches from the begin of transaction.
*/
getTransactionStatePatches(): (Pick<S, any> | S | null)[];
/**
* Starts queueing state patches off the main state. While the transaction
* is active every `setState` call has no effect on the current state.
*
* Note that call to `getState` after the transaction has begun will
* return state as it was before the transaction.
*/
beginTransaction(): void;
/**
* Applies queued state patches to the main state. All patches are squashed
* and applied with one `setState` call.
*/
commitTransaction(): void;
/**
* Cancels ongoing transaction. Uncommitted state changes are lost.
*/
cancelTransaction(): void;
}
//# sourceMappingURL=PageStateManager.d.ts.map