Skip to content

@ralphschuler.state store.StateStore.StateStore

github-actions edited this page Nov 26, 2023 · 1 revision

Class: StateStore<StateType>

@ralphschuler/state-store.StateStore.StateStore

Class responsible for managing application state and notifying listeners about changes. Utilizes Proxy for intercepting state property assignments.

Type parameters

Name Type Description
StateType extends StateProperties The type of the state this store will manage.

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new StateStore<StateType>(state): StateStore<StateType>

Initializes a new StateStore instance.

Type parameters

Name Type
StateType extends StateProperties

Parameters

Name Type Description
state StateType The initial state of the store.

Returns

StateStore<StateType>

Defined in

StateStore.ts:22

Properties

interceptors

Protected interceptors: Interceptors<StateType> = {}

Defined in

StateStore.ts:16


listeners

Protected listeners: Listeners<StateType> = {}

Defined in

StateStore.ts:14


middlewares

Protected middlewares: Middlewares<StateType> = {}

Defined in

StateStore.ts:15


state

Protected state: StateType

Defined in

StateStore.ts:13

Methods

applyInterceptors

applyInterceptors<PropertyKey>(property, value): StateType[PropertyKey]

Applies interceptors for a given property.

Type parameters

Name Type Description
PropertyKey extends string | number | symbol The key of the property for which interceptors are to be applied.

Parameters

Name Type Description
property PropertyKey The property for which interceptors should be applied.
value StateType[PropertyKey] The value to be passed through interceptors.

Returns

StateType[PropertyKey]

The value after passing through all interceptors.

Defined in

StateStore.ts:78


applyMiddlewares

applyMiddlewares<PropertyKey>(property, value, next): void

Applies middlewares for a given property.

Type parameters

Name Type Description
PropertyKey extends string | number | symbol The key of the property for which middlewares are to be applied.

Parameters

Name Type Description
property PropertyKey The property for which middlewares should be applied.
value StateType[PropertyKey] The value to be passed through middlewares.
next () => void The callback to invoke after all middlewares have been applied.

Returns

void

Defined in

StateStore.ts:97


createProxy

createProxy(): StateStore<StateType>

Creates a proxy to handle get and set operations transparently.

Returns

StateStore<StateType>

A proxy wrapped instance of the StateStore.

Defined in

StateStore.ts:31


notifyListeners

notifyListeners<PropertyKey>(property, value): void

Notifies all listeners about a change in state for a given property.

Type parameters

Name Type Description
PropertyKey extends string | number | symbol The key of the property for which listeners are to be notified.

Parameters

Name Type Description
property PropertyKey The property that has changed.
value StateType[PropertyKey] The new value of the property.

Returns

void

Defined in

StateStore.ts:125


updateState

updateState<PropertyKey>(property, value): void

Updates the state for a given property and notifies the relevant listeners. Applies interceptors and middlewares before updating the state.

Type parameters

Name Type Description
PropertyKey extends string | number | symbol The key of the property to be updated.

Parameters

Name Type Description
property PropertyKey The property to update.
value StateType[PropertyKey] The new value for the property.

Returns

void

Defined in

StateStore.ts:60

Typescript Libraries

Modules

Namespaces

Clone this wiki locally