`Updux` is a way to minimize and simplify the boilerplate associated with the creation of a `Redux` store. It takes a shorthand configuration object, and generates the appropriate reducer, actions, middleware, etc. In true `Redux`-like fashion, upduxes can be made of sub-upduxes (`subduxes` for short) for different slices of the root state.

### Type parameters

- #### S

  Store's state type. Defaults to `any`.

### Hierarchy

- Updux

## Index

### Constructors

- constructor

### Properties

- groomMutations
- initial
- subduxes

### Accessors

- actions
- asDux
- createStore
- middleware
- mutations
- reducer
- subduxUpreducer
- upreducer

### Methods

- addMutation

## Constructors

### constructor

- new Updux(config?: UpduxConfig ): Updux

- - Defined in updux.ts:109

  #### Parameters

  - ##### Default value config: UpduxConfig = {}

  #### Returns Updux

## Properties

### groomMutations

groomMutations: function

- Defined in updux.ts:99

Function that can be provided to alter all local mutations of the updux (the mutations of subduxes are left untouched).

Can be used, for example, for Immer integration:

    import Updux from 'updux';
    import { produce } from 'Immer';

    const updux = new Updux({
        initial: { counter: 0 },
        groomMutations: mutation => (...args) => produce( mutation(...args) ),
        mutations: {
            add: (inc=1) => draft => draft.counter += inc
        }
    });

Or perhaps for debugging:

    import Updux from 'updux';

    const updux = new Updux({
        initial: { counter: 0 },
        groomMutations: mutation => (...args) => state => {
            console.log( "got action ", args[1] );
            return mutation(...args)(state);
        }
    });

#### Type declaration

- - (mutation: Mutation <S>): Mutation <S>

  - #### Parameters

    - ##### mutation: Mutation <S>

    #### Returns Mutation <S>

### initial

initial: S

- Defined in updux.ts:62

Default initial state of the reducer. If applicable, merges the initial states of `config` and `subduxes`, with `config` having precedence.

If nothing was provided, defaults to an empty object.

### subduxes

subduxes: Dictionary < Updux >

- Defined in updux.ts:53

## Accessors

### actions

- get actions(): Dictionary < ActionCreator >

- - Defined in updux.ts:162

  Action creators for all actions defined or used in the actions, mutations, effects and subduxes of the updux config.

  Non-custom action creators defined in `actions` have the signature `(payload={},meta={}) => ({type, payload,meta})` (with the extra sugar that if `meta` or `payload` are not specified, the key is not present in the produced action).

  If the same action appears in multiple locations, the precedence order determining which one will prevail is

      actions generated from mutations/effects < non-custom subduxes actions <
      custom subduxes actions < custom actions

  #### Returns Dictionary < ActionCreator >

### asDux

- get asDux(): Dux <S>

- - Defined in updux.ts:258

  Returns a ducks-like plain object holding the reducer from the Updux object and all its trimmings.

  #### Returns Dux <S>

### createStore

- get createStore(): function

- - Defined in updux.ts:241

  Same as doing

      import { createStore, applyMiddleware } from 'redux';

      const { initial, reducer, middleware, actions } = updox(...);

      const store = createStore( initial, reducer, applyMiddleware(middleware) );

      for ( let type in actions ) {
          store.dispatch[type] = (...args) => {
              store.dispatch(actions[type](...args))
          };
      }

  So that later on you can do

      store.dispatch.addTodo(...);

      // still work
      store.dispatch( actions.addTodo(...) );

  #### Returns function

  - - (): StoreWithDispatchActions <S>

    - #### Returns StoreWithDispatchActions <S>

### middleware

- get middleware(): UpduxMiddleware <S>

- - Defined in updux.ts:140

  A middleware aggregating all the effects defined in the updux and its subduxes. Effects of the updux itself are done before the subduxes effects. Note that `getState` will always return the state of the local updux. The function `getRootState` is provided alongside `getState` to get the root state.

  #### Returns UpduxMiddleware <S>

### mutations

- get mutations(): Dictionary < Mutation <S>>

- - Defined in updux.ts:191

  Merge of the updux and subduxes mutations. If an action triggers mutations in both the main updux and its subduxes, the subduxes mutations will be performed first.

  #### Returns Dictionary < Mutation <S>>

### reducer

- get reducer(): function

- - Defined in updux.ts:182

  A Redux reducer generated using the computed initial state and mutations.

  #### Returns function

  - - (state: S | undefined, action: Action ): S

    - #### Parameters

      - ##### state: S | undefined

      - ##### action: Action

      #### Returns S

### subduxUpreducer

- get subduxUpreducer(): function

- - Defined in updux.ts:212

  Returns the upreducer made of the merge of all sudbuxes reducers, without the local mutations. Useful, for example, for sink mutations.

  example

        import todo from './todo'; // updux for a single todo
        import Updux from 'updux';
        import u from 'updeep';

        const todos = new Updux({ initial: [], subduxes: { '*': todo } });
        todos.addMutation(
            todo.actions.done,
            ({todo_id},action) => u.map( u.if( u.is('id',todo_id) ), todos.subduxUpreducer(action) )
            true
        );

  #### Returns function

  - - (action: Action ): function

    - #### Parameters

      - ##### action: Action

      #### Returns function

      - - (state: S): S

        - #### Parameters

          - ##### state: S

          #### Returns S

### upreducer

- get upreducer(): Upreducer <S>

- - Defined in updux.ts:174

  #### Returns Upreducer <S>

## Methods

### addMutation

- addMutation<A>(creator: A, mutation: Mutation <S, A extends (...args: any[]) => infer R ? R : never>, isSink?: undefined | false | true): void

- - Defined in updux.ts:283

  Adds a mutation and its associated action to the updux. If a local mutation was already associated to the action, it will be replaced by the new one.

  example

        updux.addMutation( add, inc => state => state + inc );

  #### Type parameters

  - #### A: ActionCreator

  #### Parameters

  - ##### creator: A

  - ##### mutation: Mutation <S, A extends (...args: any[]) => infer R ? R : never>

  - ##### Optional isSink: undefined | false | true

    If `true`, disables the subduxes mutations for this action. To conditionally run the subduxes mutations, check out subduxUpreducer.

  #### Returns void

Generated using TypeDoc