Store's state type. Defaults to any
.
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);
}
});
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.
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
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(...) );
A middleware aggregating all the effects defined in the updux and its subduxes. Effects of the updux itself are done before the subduxes effects.
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.
A Redux reducer generated using the computed initial state and mutations.
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.
Generated using TypeDoc
Updux
is a way to minimize and simplify the boilerplate associated with the creation of aRedux
store. It takes a shorthand configuration object, and generates the appropriate reducer, actions, middleware, etc. In trueRedux
-like fashion, upduxes can be made of sub-upduxes (subduxes
for short) for different slices of the root state.