Options
All
  • Public
  • Public/Protected
  • All
Menu

Module types

Index

Primary API Type aliases

Store

Store<S, A>: { addReducer: AddReducer<S, A>; addSubReducer: AddSubReducer<S, A>; dispatch: Dispatcher<S, A>; getState: GetState<S>; subscribe: Subscribe<S, A> }

Type parameters

Type declaration

StoreReact

StoreReact<S, A>: { StoreContext: React.Context<Store<S, A> | null>; useAction: UseAction<S, A>; useActionCreator: UseActionCreator<A>; useDispatch: UseDispatch<S, A>; useSelector: UseSelector<S>; useStore: UseStore<S, A> }

Type parameters

Type declaration

Store API Type aliases

AddReducer

AddReducer<S, A>: (reducer: Reducer<S, A>) => () => void

Add a reducer to be ran on dispatches

param

The reducer to be added

returns

Function to remove the given reducer, no longer running it upon dispatches

Type parameters

Type declaration

    • (reducer: Reducer<S, A>): () => void
    • Parameters

      Returns () => void

        • (): void
        • Returns void

AddSubReducer

AddSubReducer<S, A>: <K>(key: K, reducer: Reducer<S[K], A>) => () => void

Add a reducer to be ran on dispatches updating a property of State rather than the whole object.

param

The property of State this reducer is targeting

param

The reducer to be added

returns

Function to remove the given reducer

Type parameters

Type declaration

    • <K>(key: K, reducer: Reducer<S[K], A>): () => void
    • Type parameters

      • K: keyof S

      Parameters

      Returns () => void

        • (): void
        • Returns void

Dispatcher

Dispatcher<S, A>: (action: A | ActionThunk<S, A>) => void
  • Action - Pass the action to the reducers, updating the state, triggering the subscribers.
  • ActionThunk - Execute the thunk, passing Dispatcher & GetState
param

The action to run the reducers with

returns

void Fire & Forget

Type parameters

Type declaration

GetState

GetState<S>: () => S

Return the current state value

Type parameters

  • S

Type declaration

    • (): S
    • Returns S

Subscribe

Subscribe<S, A>: (cb: Subscriber<S, A>) => () => void

Subscribe to the store. The given callback is ran after every dispatch() call.

param

Callback to run after dispatches

returns

Function to deregister the callback

Type parameters

Type declaration

    • (cb: Subscriber<S, A>): () => void
    • Parameters

      • cb: Subscriber<S, A>

      Returns () => void

        • (): void
        • Returns void

React Type aliases

UseAction

UseAction<S, A>: (action: A | ActionThunk<S, A>) => () => void

Create a callback to dispatch the given action

param

Once given, this action is set (Not registered in useCallback dependencies). Action to dispatch.

returns

React Callback - A callback which will dispatch the given action. Wrapped in useCallback.

example
const clearFilters = useAction({type: "CLEAR_FILTERS"});
clearFilters();

Type parameters

Type declaration

    • Parameters

      Returns () => void

        • (): void
        • Returns void

UseActionCreator

UseActionCreator<A>: <B>(actionCreator: (b: B) => A, additionalDeps?: any[]) => (b: B) => void

Create a callback which runs the given action creator and dispatches it's action result

param

Once given, this function is set (Not registered in useCallback dependencies). A function which takes any value and returns an action to be dispatched

example
const setEmailAddress = useActionCreator<string>(
    email => ({type: "SET_EMAIL", email})
);
setEmailAddress("emailaddress");

Type parameters

Type declaration

    • <B>(actionCreator: (b: B) => A, additionalDeps?: any[]): (b: B) => void
    • Type parameters

      • B = void

      Parameters

      • actionCreator: (b: B) => A
          • (b: B): A
          • Parameters

            • b: B

            Returns A

      • Optional additionalDeps: any[]

      Returns (b: B) => void

        • (b: B): void
        • Parameters

          • b: B

          Returns void

UseDispatch

UseDispatch<S, A>: () => Dispatcher<S, A>
returns

The Store.dispatch from the React Context

example
const dispatch = useDispatch();
dispatch(myAction|myThunk);

Type parameters

Type declaration

UseSelector

UseSelector<S>: <A>(selector: Selector<S, A>) => A

Subscribe to the Store and run the selector upon state changes

param

The selector to run

example
const foo = useSelector(fooSelector);

Type parameters

  • S

Type declaration

    • Type parameters

      • A

      Parameters

      Returns A

UseStore

UseStore<S, A>: () => Store<S, A>
returns

The Store from the React Context

example
const store = useStore();

Type parameters

Type declaration

Other Type aliases

ActionThunk

ActionThunk<S, A>: (getState: GetState<S>, dispatcher: Dispatcher<S, A>) => void

A function taking getState and a dispatcher allowing for multiple dispatches and up to date reads. Useful for async patterns. See redux-thunk.

Type parameters

Type declaration

InquirerReact

InquirerReact<Q>: { QueryContext: React.Context<Inquirier<Q> | null>; useInquirierEmitter: () => RunQuery<Q>; useInquirierResponder: (tag: RegisterQueryResponderArgs<Q>[0], cb: RegisterQueryResponderArgs<Q>[1], additionalDeps: any[]) => void }

Type parameters

Type declaration

Inquirier

Inquirier<Q>: { query: RunQuery<Q>; register: RegisterQueryResponder<Q> }

Type parameters

Type declaration

Memoize

Memoize: <Args, R>(fn: (...args: Args) => R) => (...args: Args) => R

Variadic memoize function. Takes and returns a function, prevserving it's type signature whilt applying memoization to it.

Type declaration

    • <Args, R>(fn: (...args: Args) => R): (...args: Args) => R
    • Type parameters

      • Args: any[]

      • R

      Parameters

      • fn: (...args: Args) => R
          • (...args: Args): R
          • Parameters

            • Rest ...args: Args

            Returns R

      Returns (...args: Args) => R

        • (...args: Args): R
        • Parameters

          • Rest ...args: Args

          Returns R

Query

Query: { result: any; tag: string }

Type declaration

  • result: any
  • tag: string

QueryResponder

QueryResponder<Q>: (query: Omit<Q, "result">) => Q["result"]

Type parameters

Type declaration

    • (query: Omit<Q, "result">): Q["result"]
    • Parameters

      • query: Omit<Q, "result">

      Returns Q["result"]

RegisterQueryResponder

RegisterQueryResponder<Q>: (args: RegisterQueryResponderArgs<Q>[0], args2: RegisterQueryResponderArgs<Q>[1]) => () => void

Type parameters

Type declaration

RegisterQueryResponderArgs

RegisterQueryResponderArgs<Q>: Q extends any ? [Q["tag"], QueryResponder<Q>] : [never]

Type parameters

RunQuery

RunQuery<Q>: (query: Omit<Q, "result">) => Q["result"][]

Type parameters

Type declaration

    • (query: Omit<Q, "result">): Q["result"][]
    • Parameters

      • query: Omit<Q, "result">

      Returns Q["result"][]

Selector

Selector<S, A>: (s: S) => A

Function from S to A

Type parameters

  • S

  • A

Type declaration

    • (s: S): A
    • Parameters

      • s: S

      Returns A

Inferred Type aliases

Action

Action: { type: string }

The base type for a tagged union via the type property.

Type declaration

  • type: string

ActionHandlers

ActionHandlers<S, A>: A extends any ? Partial<Record<A["type"], Reducer<S, A>>> : never

A record keyed by Actions where the value is a reducer taking that action. See reducerFromHandlers for usage.

Type parameters

Reducer

Reducer<S, A>: (state: S, action: A) => S

Classical reducer. Takes state & an action returs a new state.

Type parameters

Type declaration

    • (state: S, action: A): S
    • Parameters

      • state: S
      • action: A

      Returns S

Generated using TypeDoc