Skip to content

Latest commit

 

History

History
93 lines (64 loc) · 3.48 KB

API.md

File metadata and controls

93 lines (64 loc) · 3.48 KB

API Documentation

Common API (Angular/React/Svelte/Vue)

createSubState

export default function createSubState<T extends InitialState>(
  initialState: T & AllowedInitialStateProperties<T>
): SubState

Creates a sub state object from initial state object.
This function adds a readonly __isSubState__ property to the initial state object.
Initial state may not contain key __isSubState__, if it contains, an error will be thrown.
Initial state must be an object with following property value types allowed: number, boolean, string, undefined, null, Function, object, Array, Map, Set, WeakMap, WeakSet

combineSelectors

combineSelectors<T extends State, U1 extends SelectorsBase<T>, ... Un extends SelectorsBase<T>>(
  selectorsObject1: Selectors<T, U1>,
  ...
  selectorsObject2: Selectors<T, Un>
): Selectors<T, U1> & ... Selectors<T, Un>;

combines objects of selectors to a single object containing all selectors
It also checks for duplicate selector keys and throws an error if a duplicate key is found.

createStore

createStore<T extends State, U extends SelectorsBase<T>>(
  initialState: T,
  selectors: Selectors<T, U>
): Store<T, U>

creates a store containing initialState and selectors

Store::getState

class Store<T extends State, U extends SelectorsBase<T>> {
  getState(): ReactiveState<T>
}

gets state from the store

Store::getSelectors

class Store<T extends State, U extends SelectorsBase<T>> {
  getSelectors(): ComputedSelectors<T, U>
}

gets selectors from the store

Store::getStateAndSelectors

class Store<T extends State, U extends SelectorsBase<T>> {
  getStateAndSelectors(): [ReactiveState<T>, ComputedSelectors<T, U>]
}

gets state and selectors from the store

Angular specific API

Store::useState

useState<V extends new (...args: any[]) => any>(
  componentInstance: InstanceType<V>,
  subStateOrStateGetterMap: { [key: string]: SubState | StateGetter }
): void

makes given Angular component instance to use sub-state(s) or state getters given in subStateOrStateGetterMap and makes changes to given sub-state(s) and state getter(s) to update the view.
Note! If you call only getState() and forget to call useState(), your view won't be reactive and does not update.

Store::useSelectors

useSelectors<V extends new (...args: any) => any>(
  componentInstance: InstanceType<V>,
  selectorMap: { [key: string]: ComputedRef }
): void 

makes given Angular component instance to use selectors given in selectorMap and makes changes to given selectors to update the view.
Note! If you call only getSelectors() and forget to call useSelectors(), your view won't be reactive and does not update.

Store::useStateAndSelectors

useStateAndSelectors<V extends new (...args: any[]) => any>(
  componentInstance: InstanceType<V>,
  subStateOrStateGetterMap: { [key: string]: SubState | StateGetter },
  selectorMap: { [key: string]: ComputedRef }
): void

makes given Angular component instance to use sub-state(s), state getters and selectors given in subStateOrStateGetterMap and selectorMap and makes changes to given sub-state(s), or state getter(s) and selectors to update the view.
Note! If you call only getStateAndSelectors() and forget to call useStateAndSelectors(), your view won't be reactive and does not update.