Skip to main content

Class: PageStateManager<S>

@ima/core.PageStateManager

Manager of the current page state and state history.

Type parameters

NameType
Sextends PageState = {}

Hierarchy

Constructors

constructor

new PageStateManager<S>()

Type parameters

NameType
Sextends PageState = {}

Properties

onChange

Optional onChange: (newState: S) => void

Type declaration

▸ (newState): void

Parameters
NameType
newStateS
Returns

void

Defined in

packages/core/src/page/state/PageStateManager.ts:7

Methods

beginTransaction

beginTransaction(): void

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.

Returns

void

Defined in

packages/core/src/page/state/PageStateManager.ts:64


cancelTransaction

cancelTransaction(): void

Cancels ongoing transaction. Uncommitted state changes are lost.

Returns

void

Defined in

packages/core/src/page/state/PageStateManager.ts:79


clear

clear(): void

Clears the state history.

Returns

void

Defined in

packages/core/src/page/state/PageStateManager.ts:12


commitTransaction

commitTransaction(): void

Applies queued state patches to the main state. All patches are squashed and applied with one setState call.

Returns

void

Defined in

packages/core/src/page/state/PageStateManager.ts:72


getAllStates

getAllStates(): 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.

Returns

S[]

The recorded history of page states.

Defined in

packages/core/src/page/state/PageStateManager.ts:44


getState

getState(): S

Returns the current page state.

Returns

S

The current page state.

Defined in

packages/core/src/page/state/PageStateManager.ts:31


getTransactionStatePatches

getTransactionStatePatches(): (null | S | Pick<S, any>)[]

Returns queueing state patches off the main state from the begin of transaction.

Returns

(null | S | Pick<S, any>)[]

State patches from the begin of transaction.

Defined in

packages/core/src/page/state/PageStateManager.ts:53


setState

setState<K>(patchState): void

Sets a new page state by applying the provided patch to the current state.

Type parameters

NameType
Kextends string | number | symbol

Parameters

NameType
patchStatenull | S | Pick<S, K>

Returns

void

Defined in

packages/core/src/page/state/PageStateManager.ts:22