Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Store<ST>

The store class. You can have multiple stores, even if merged to simplify access different instances exist. The store receives dispatch calls to mutate the store. Each property is handled separately. If one changes through a reducer, the subscriber event fires. This returns the whole store, but only the one property you currently subscribe to has it's new value already; all others remain until they receive their values. That happens even if the reducer returns multiple values in one single step. To assure a fully mutated object

Type parameters

  • ST: object

Hierarchy

  • Store

Index

Constructors

constructor

Accessors

actions

id

  • get id(): string

reducer

  • get reducer(): Map<ActionKey, (state: any, payload: any, actionKey?: ActionKey) => Promise<any> | any>

state

  • get state(): any

status

Methods

dispatch

  • dispatch(actionKey: ActionKey, payload?: any): Promise<boolean>
  • A dispatcher for actions that looks in the actions collection and runs the action if it can find it

    memberof

    Store Store

    Parameters

    • actionKey: ActionKey

      The key to initiate the action, must have a corresponding entry in the reducer object

    • Optional payload: any

      An optional payload that provides data for the action

    Returns Promise<boolean>

    Returns true for success or false if the action could not dispatch properly (see warnings)

dispatched

  • dispatched(cb: (value: ST) => void): void
  • The final event that shows that all mutations of a reducer call are done. Returns the fully mutated store.

    Parameters

    • cb: (value: ST) => void

      A callback function to receive the complete store.

        • (value: ST): void
        • Parameters

          • value: ST

          Returns void

    Returns void

dispose

  • dispose(specific?: keyof ST & string): void
  • Remove (dispose) all the subscribers for all store states.

    Parameters

    • Optional specific: keyof ST & string

      A state property, for which you wish to dispose all the subscribers. Can be ommited.

    Returns void

mergeStore

  • Merge this store with another one. This is useful to have distributed definitions, sub-stores per component actually, but can still work with one single global store - the single source of truth.

    Type parameters

    • T

    Parameters

    Returns Store<ST & T>

subscribe

  • subscribe(storeProperty: keyof ST & string, cb: (value: ST) => void): { remove: () => void }
  • Subscribe here for store changes. Don't forget to call remove on dispose. The subscriber must be destroyed if the defining component is disposed or removed from DOM. To do so, capture the returned object. It contains a function remove() you can call, then.

    Parameters

    • storeProperty: keyof ST & string

      Subscribe to any property of the store defined by store type and only in string form.

    • cb: (value: ST) => void

      The callback that will be called when a change happened. Parameter is the current state object. The callback may not return anything.

        • (value: ST): void
        • Parameters

          • value: ST

          Returns void

    Returns { remove: () => void }

    • remove: () => void
        • (): void
        • Returns void

Generated using TypeDoc