license import { Action } from "./Action" ; import { Reducer } from "./Reducer" ; import { TypedAction } from "./TypedAction" ; import { TypedActionDefinition2 } from "./TypedActionDefinition2" ; import { TypedActionString } from "./TypedActionString" ; import { TypedReducerBuilderImpl } from "./internal/TypedReducerBuilderImpl" ; /**
 * Important utility to help build Redux Reducer functions
 * when you have TypedActions available. In contrast to normal
 * reducer writing, the TypedReducer gives strong type inferencing
 * in each of your Action type branches.
 */ export namespace TypedReducer { /**
     * Builder interface for constructing Reducers using TypedActions.
     * Consumers should define their reducer using a sequence of `.withHandler()`,
     * `.withActionHandler()`, and `.withDefaultHandler()` before invoking `build()`.
     */ export interface Builder < S > { /**
         * Most common builder method that associates a handler for
         * a given type of Action. This builder method will present the Action's
         * payload for the consumer.
         *
         * In practice, specific Action Reducers depend only on the associated payload,
         * and unwrapping that once allows for compact syntax for destructuring:
         *
         *
         * ```
         * const reducer = TypedReducer.builder<State>();
         *
         * reducer.withHandler(SetResultsAction.TYPE, (state, {results, areMoreAvailable}) => {
         *   return setWith(state, {results, areMoreAvailable});
         * });
         *
         * reducer.withHandler(ClearResultsAction.TYPE, (state, {id}) => {
         *   return setWith(state, {
         *     history: omit(state.history, id)
         *   });
         * });
         *
         * return reducer.build();
         * ```
         *
         *
         * It is an error to specify more than one handler for the same kind of action.
         */ withHandler < T > ( type , handler ) : this ; /**
         * Alias for withHandler that takes the whole action definition rather than just the type string.
         */ withDefinitionHandler < T , E extends string > ( type , handler ) : this ; /**
         * Similar to `.withHandler()`, but gives the raw Action itself (instead
         * of unwrapping the payload). Used often when building higher order reducers
         * that will ferry the action down to delegates or similar.
         *
         * It is an error to specify more than one handler for the same kind of action.
         */ withActionHandler < T , E extends string = string > ( type , handler ) : this ; /**
         * Optional fallback branch during reduction, which will pass the unhandled
         * action to the given handler. This "default" handler will not be invoked
         * if there was a handler supplied to `reducing()` or `reducingAction()`
         * for the `action`.
         *
         * It is an error to specify more than one `reducingDefault()` to the same Builder.
         */ withDefaultHandler ( handler ) : this ; /**
         * Returns the Reducer backed by all of the handlers defined on this Builder.
         * It is an error to re-use this Builder instance to create more Reducers.
         */ build ( ) : Reducer < S > ; } /**
     * Returns a new instance of a TypedReducer.Builder.
     */ export function builder < S > ( ) { return new TypedReducerBuilderImpl < S > ( ) ; } }