updux/docs
2021-10-15 12:41:58 -04:00
..
API wip 2021-10-15 12:41:58 -04:00
assets wip 2021-10-15 12:41:58 -04:00
classes compile 2019-11-06 19:07:06 -05:00
fonts wip 2021-10-12 13:11:32 -04:00
interfaces compile 2019-11-06 19:07:06 -05:00
scripts wip 2021-10-15 12:41:58 -04:00
styles wip 2021-10-12 13:11:32 -04:00
typedoc going toward v2 2020-06-02 16:00:48 -04:00
_sidebar.md documentation, actions 2021-10-12 18:13:59 -04:00
.nojekyll move documentation to docsify 2020-01-31 17:24:57 -05:00
concepts.md finished going over the tutorial 2021-10-13 19:31:37 -04:00
exports.md going toward v2 2020-06-02 16:00:48 -04:00
globals.html compile 2019-11-06 19:07:06 -05:00
index.html wip 2021-10-12 14:49:08 -04:00
index.js.html wip 2021-10-12 13:11:32 -04:00
module-updux.html wip 2021-10-12 13:11:32 -04:00
README.md documentation, actions 2021-10-12 18:13:59 -04:00
recipes.md a few more grammar typos 2020-06-04 15:08:49 -04:00
tutorial.md finished going over the tutorial 2021-10-13 19:31:37 -04:00
Updux.html wip 2021-10-12 13:11:32 -04:00
Updux.js.html wip 2021-10-12 13:11:32 -04:00

What's Updux?

So, I'm a fan of Redux.

As I was looking into tools to help cut on its boilerplate, I came across rematch. It has some pretty darn good ideas. But it also enforces a flat hierarchy of reducers -- where is the fun in that?

I'm also having a strong love for Updeep, so I wanted a framework where I could use it to define reducer state updates.

Hence: Updux. Heavily inspired by rematch, but twisted to work with updeep and to fit my peculiar needs. It offers features such as

  • Mimic the way VueX has mutations (per-action reducer logic) and effects (middleware reacting to actions that can be asynchronous and/or have side-effects), so all things pertaining to a store are defined in the space place.
  • Automatically gather all actions used by the updux's effects and mutations, and makes then accessible as attributes to the dispatch object of the store.
  • Mutations have a signature that is friendly to Updux and Immer.
  • Mutations auto-unwrapping the payload of actions for you.
  • TypeScript support.

Fair warning: this package is still very new, likely to go through big changes before I find the perfect balance between ease of use and sanity. Caveat Emptor.

Synopsis

import { Updux } from 'updux';
import u from 'updeep';
import add from 'lodash/fp/add.js';

import otherDux from './otherUpdux';

const dux = new Updux({
    initial: {
        counter: 0,
    },
    actions: {
        inc: null
    },
    subduxes: {
        otherDux,
    }
});

dux.setMutation('inc', (increment) => u({ counter: add(increment) }));

dux.addEffect( '*', api => next => action => {
    console.log( "hey, look, an action zoomed by!", action );
    next(action);
} );

const store = dux.createStore();

store.dispatch.inc(1);

console.log( store.getState().counter ); // prints 1