Options
All
  • Public
  • Public/Protected
  • All
Menu

updux

Index

Type aliases

Action

Action<T, P>: object & MaybePayload<P>

Type parameters

  • T: string

  • P

ActionCreator

ActionCreator<T, P>: object & function

Type parameters

  • T: string

  • P

ActionPair

ActionPair: [string, ActionCreator]

ActionPayloadGenerator

ActionPayloadGenerator: function

Type declaration

    • (...args: any[]): any
    • Parameters

      • Rest ...args: any[]

      Returns any

Dictionary

Dictionary<T>: object

Type parameters

  • T

Type declaration

  • [key: string]: T

Dux

Dux<S>: Pick<Updux<S>, "subduxes" | "actions" | "initial" | "mutations" | "reducer" | "middleware" | "createStore" | "upreducer">

Type parameters

  • S

MaybePayload

MaybePayload<P>: MaybePayload<P>

Type parameters

  • P

Mutation

Mutation<S, A>: function

Type parameters

Type declaration

    • (payload: A["payload"], action: A): function
    • Parameters

      • payload: A["payload"]
      • action: A

      Returns function

        • (state: S): S
        • Parameters

          • state: S

          Returns S

Next

Next: function

Type declaration

    • Parameters

      Returns any

StoreWithDispatchActions

StoreWithDispatchActions<S, Actions>: Store<S> & object

Type parameters

  • S

  • Actions

SubMutations

SubMutations: object

Type declaration

UpduxConfig

UpduxConfig<S>: object

Configuration object given to Updux's constructor.

Type parameters

  • S

    Type of the Updux's state. Defaults to any.

Type declaration

  • Optional actions?: undefined | object

    Generic action creations are automatically created from the mutations and effects, but you can also define custom action creator here. The object's values are function that transform the arguments of the creator to the action's payload.

    const { actions } = updox({
        mutations: {
            foo: () => state => state,
        }
        actions: {
            bar: (x,y) => ({x,y})
        }
    });
    
    actions.foo({ x: 1, y: 2 }); // => { type: foo, payload: { x:1, y:2  } }
    actions.bar(1,2);            // => { type: bar, payload: { x:1, y:2  } }
  • Optional effects?: Dictionary<UpduxMiddleware<S>>

    Plain object defining asynchronous actions and side-effects triggered by actions. The effects themselves are Redux middleware, expect with the dispatch property of the first argument augmented with all the available actions.

    updux({
        effects: {
            fetch: ({dispatch}) => next => async (action) => {
                next(action);
    
                let result = await fetch(action.payload.url).then( result => result.json() );
                dispatch.fetchSuccess(result);
            }
        }
    });
  • Optional groomMutations?: undefined | function
  • Optional initial?: S

    The default initial state of the reducer. Can be anything your heart desires.

  • Optional mutations?: any

    Object mapping actions to the associated state mutation.

    For example, in Redux you'd do

    function todosReducer(state=[],action) {
    
        switch(action.type) {
            case 'ADD':  return [ ...state, action.payload ];
    
            case 'DONE': return state.map( todo => todo.id === action.payload
                ? { ...todo, done: true } : todo )
    
            default: return state;
        }
    }

    With Updux:

    const todosUpdux = updux({
        mutations: {
            add: todo => state => [ ...state, todo ],
            done: done_id => u.map( u.if( ({id} => id === done_id), {done: true} ) )
        }
    });

    The signature of the mutations is (payload,action) => state => newState. It is designed to play well with Updeep (and Immer). This way, instead of doing

        mutation: {
            renameTodo: newName => state => { ...state, name: newName }
        }

    we can do

        mutation: {
            renameTodo: newName => u({ name: newName })
        }

    Also, the special key * can be used to match any action not explicitly matched by other mutations.

    const todosUpdux = updux({
        mutations: {
            add: todo => state => [ ...state, todo ],
            done: done_id => u.map( u.if( ({id} => id === done_id), {done: true} ) ),
            '*' (payload,action) => state => {
                console.warn( "unexpected action ", action.type );
                return state;
            },
        }
    });
  • Optional subduxes?: undefined | __type

    Object mapping slices of the state to sub-upduxes.

    For example, if in plain Redux you would do

    import { combineReducers } from 'redux';
    import todosReducer from './todos';
    import statisticsReducer from './statistics';
    
    const rootReducer = combineReducers({
        todos: todosReducer,
        stats: statisticsReducer,
    });

    then with Updux you'd do

    import { updux } from 'updux';
    import todos from './todos';
    import statistics from './statistics';
    
    const rootUpdux = updux({
        subduxes: {
            todos, statistics
        }
    });

UpduxDispatch

UpduxDispatch: Dispatch & Dictionary<Function>

UpduxMiddleware

UpduxMiddleware<S>: function

Type parameters

  • S

Type declaration

Upreducer

Upreducer<S>: function

Type parameters

  • S

Type declaration

    • Parameters

      Returns function

        • (state: S): S
        • Parameters

          • state: S

          Returns S

Functions

Const MiddlewareFor

  • MiddlewareFor(type: any, mw: Middleware): Middleware

actionCreator

  • actionCreator<T, P>(type: T, transform: function): ActionCreator<T, P>
  • actionCreator<T>(type: T, transform: never): ActionCreator<T, undefined>
  • actionCreator<T>(type: T, transform: null): ActionCreator<T, null>

actionFor

buildActions

buildCreateStore

  • buildCreateStore<S>(reducer: Reducer<S>, initial: S, middleware: Middleware, actions: Dictionary<ActionCreator>): (Anonymous function)

buildInitial

  • buildInitial<S>(initial: S, subduxes?: Dictionary<undefined>): S
  • buildInitial<S>(initial?: Partial<S>, subduxes?: Partial<S>): S extends object ? S : never
  • Type parameters

    • S: number | string | boolean

    Parameters

    • initial: S
    • Optional subduxes: Dictionary<undefined>

    Returns S

  • Type parameters

    • S: object

    Parameters

    • Optional initial: Partial<S>
    • Optional subduxes: Partial<S>

    Returns S extends object ? S : never

buildMiddleware

buildMutations

  • buildMutations(mutations?: Dictionary<Mutation | Object>, subduxes?: object): Dictionary<function>

buildUpreducer

Const composeMutations

  • composeMutations(mutations: Mutation[]): function
  • Parameters

    Returns function

      • (payload: A["payload"], action: A): function
      • Parameters

        • payload: A["payload"]
        • action: A

        Returns function

          • (state: S): S
          • Parameters

            • state: S

            Returns S

sliceMw

  • sliceMw(slice: string, mw: Middleware): Middleware

Generated using TypeDoc