UNPKG

typesafe-actions-reducer-builder

Version:

Reducer builder for typesafe-actions, including immer for reducer's output

31 lines 2.35 kB
import { ActionCreatorBuilder, EmptyAction, PayloadAction, PayloadMetaAction, TypeConstant } from 'typesafe-actions'; import { Reducer, AnyAction } from 'redux'; declare type ActionT<TPayload extends any = undefined, TMeta extends any = undefined> = [TMeta] extends [undefined] ? [TPayload] extends [undefined] ? EmptyAction<TypeConstant> : PayloadAction<TypeConstant, TPayload> : [TPayload] extends [undefined] ? PayloadMetaAction<TypeConstant, undefined, TMeta> : PayloadMetaAction<TypeConstant, TPayload, TMeta>; declare type ActionCreatorBuilderT<TPayload extends any = undefined, TMeta extends any = undefined> = [TMeta] extends [undefined] ? [TPayload] extends [undefined] ? ActionCreatorBuilder<TypeConstant> : ActionCreatorBuilder<TypeConstant, TPayload> : [TPayload] extends [undefined] ? ActionCreatorBuilder<TypeConstant, undefined, TMeta> : ActionCreatorBuilder<TypeConstant, TPayload, TMeta>; interface ReducerBuilderHandler<TState, TPayload, TMeta> { reducer(reducer: Reducer<TState, ActionT<TPayload, TMeta>>): ReducerBuilderHandler<TState, TPayload, TMeta>; handle: ReducerBuilderHandlerBuilder<TState>; build(): Reducer<TState, AnyAction>; } declare type ReducerBuilderHandlerBuilder<TState> = <TPayload = undefined, TMeta = undefined>(actionCreatorBuilder: ActionCreatorBuilderT<TPayload, TMeta>) => ReducerBuilderHandler<TState, TPayload, TMeta>; interface ReducerBuilder<TState> { build(): Reducer<TState, AnyAction>; handle: ReducerBuilderHandlerBuilder<TState>; } /** * Create a reducer builder, starting from its state. * It supports multiple actions (from typesafe-actions) with multiple reducers. * When the reducers are all set, just call build() to create the root reducer. * * It uses immer, which will produce an Immutable<TState> object as the result * of the reducer. The developer should edit the state in the reducer, instead * of creating a new one: immer will take care of creating a new object. * * The builder will provide type hints along all the build structure, lowering * the possibility of creating bugs. * * @param initialState the reducer's initial state */ declare function createReducerBuilder<TState>(initialState: TState): ReducerBuilder<TState>; export default createReducerBuilder; //# sourceMappingURL=createReducerBuilder.d.ts.map