Skip to main content

Class: PageStateManagerImpl<S>

@ima/core.PageStateManagerImpl

The implementation of the PageStateManager interface.

Type parameters

NameType
Sextends PageState = {}

Hierarchy

Constructors

constructor

new PageStateManagerImpl<S>(dispatcher)

Initializes the page state manager.

Type parameters

NameType
Sextends PageState = {}

Parameters

NameTypeDescription
dispatcherDispatcherDispatcher fires events to app.

Overrides

PageStateManager.constructor

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:40

Properties

_cursor

Private _cursor: number = -1

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:25


_dispatcher

Private _dispatcher: Dispatcher

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:26


_ongoingTransaction

Private _ongoingTransaction: boolean = false

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:27


_statePatchQueue

Private _statePatchQueue: (null | S | Pick<S, any>)[] = []

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:28


_states

Private _states: S[] = []

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:29


onChange

Optional onChange: (newState: S) => void

Type declaration

▸ (newState): void

Parameters
NameType
newStateS
Returns

void

Inherited from

PageStateManager.onChange

Defined in

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

Accessors

$dependencies

Static get $dependencies(): typeof Dispatcher[]

Returns

typeof Dispatcher[]

Defined in

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

Methods

_callOnChangeCallback

_callOnChangeCallback(newState): void

Call registered callback function on (@link onChange) with newState.

Parameters

NameType
newStateS

Returns

void

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:175


_eraseExcessHistory

_eraseExcessHistory(): void

Erase the oldest state from storage only if it exceed max defined size of history.

Returns

void

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:157


_pushToHistory

_pushToHistory(newState): void

Push new state to history storage.

Parameters

NameType
newStateS

Returns

void

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:167


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

Overrides

PageStateManager.beginTransaction

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:106


cancelTransaction

cancelTransaction(): void

Cancels ongoing transaction. Uncommitted state changes are lost.

Returns

void

Overrides

PageStateManager.cancelTransaction

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:148


clear

clear(): void

Clears the state history.

Returns

void

Overrides

PageStateManager.clear

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:49


commitTransaction

commitTransaction(): void

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

Returns

void

Overrides

PageStateManager.commitTransaction

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:123


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.

Overrides

PageStateManager.getAllStates

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:92


getState

getState(): S

Returns the current page state.

Returns

S

The current page state.

Overrides

PageStateManager.getState

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:85


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.

Overrides

PageStateManager.getTransactionStatePatches

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:99


setState

setState<K>(patchState): number | 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

number | void

Overrides

PageStateManager.setState

Defined in

packages/core/src/page/state/PageStateManagerImpl.ts:59