Options
All
  • Public
  • Public/Protected
  • All
Menu

@iadvize-oss/store - v1.1.1

Index

Type aliases

Listener

Listener<State>: (state: State) => void

Type parameters

  • State

Type declaration

    • (state: State): void
    • Parameters

      • state: State

      Returns void

Reducer

Reducer<State>: (state: State) => State

Type parameters

  • State

Type declaration

    • (state: State): State
    • Parameters

      • state: State

      Returns State

Store

Store<State>: { apply: any; read: any; subscribe: any }

Type parameters

  • State

Type declaration

  • apply: function
    • apply(reducer: Reducer<State>): () => void
    • Apply a reducer on the state and update the store current state with the result

      example

      import * as Store from 'store';

      const store = Store.create(() => 2)();

      store.apply(state => state + 1)();

      store.read() // 3

      Parameters

      Returns () => void

        • (): void
        • Returns void

  • read: function
    • read(): State
    • Read the store current state

      example

      import * as Store from 'store';

      const store = Store.create(() => 2)();

      store.read() // 2

      Returns State

  • subscribe: function
    • Subscribe a listener to state changes

      The subscription returns a function to call to unsubscribe.

      example

      import * as Store from 'store';

      const store = Store.create(() => 2)();

      const subscribe = store.subscribe(() => console.log('hello world'));

      const unsubscribe = subscribe();

      store.apply(state => state + 1)();

      // hello world

      unsubscribe();

      store.apply(state => state + 1)();

      Parameters

      Returns () => Unsubscribe

Unsubscribe

Unsubscribe: () => void

Type declaration

    • (): void
    • Returns void

Functions

create

  • create<State>(setupInitialState: () => State): () => Store<State>
  • Store creation with a initialState

    example

    import * as Store from 'store';

    const createNumberStore = Store.create(() => 2);

    const store = createNumberStore();

    Type parameters

    • State

    Parameters

    • setupInitialState: () => State
        • (): State
        • Returns State

    Returns () => Store<State>

      • Store creation with a initialState

        Returns Store<State>

liftAndApply

  • liftAndApply<State, Fn>(fn: Fn, store: Store<State>): (...args: Parameters<Fn>) => () => void
  • Lift and apply a reducer factory, returning a function that, given some arguments, will apply the reducer on the state and update the store current state with the result

    example

    import * as Store from 'store';

    const store = Store.create(() => 2)();

    // instead of: const add = (n: number) => store.apply(state => state + n);

    // write: const add = Store.liftAndApply((n: number) => state => state + n, store);

    add(2)(); store.read() // 4

    Type parameters

    • State

    • Fn: (...args: any[]) => Reducer<State>

    Parameters

    • fn: Fn
    • store: Store<State>

    Returns (...args: Parameters<Fn>) => () => void

      • (...args: Parameters<Fn>): () => void
      • Lift and apply a reducer factory, returning a function that, given some arguments, will apply the reducer on the state and update the store current state with the result

        Parameters

        • Rest ...args: Parameters<Fn>

        Returns () => void

          • (): void
          • Returns void

Generated using TypeDoc