redux-action-fold

0.1.1 • Public • Published

redux-action-fold

Utility functions to help alleviate redux boilerplate.

const F = require ('redux-action-fold');

// :: State = String

// :: StrMap (a => Action a)
const Action = 
  F.unfold ([ 'Move'
            , 'Die'
            , 'Spawn'
            ]);

// :: State -> Action -> State
const reducer = state =>
  F.fold ({ Move: ({ x, y }) => S.concat (state) (`Go to ${x}:${y}`)
          , Die: () => S.concat (state) ('☠︎')
          });

// :: Action
const a = Action.Move ({ x: 1, y: 10 });

// :: Action
const b = Action.Die ();

// :: Action
const c = { type: 'Spawn', payload: null };

// :: State
reducer ('Player 1: ') (a); //=> 'Player 1: Go to 1:10'
reducer ('Player 2: ') (b); //=> 'Player 2: ☠︎'
reducer ('Player 3: ') (c); //=> Throw: 'Spawn' action not handled in fold.

Package Sidebar

Install

npm i redux-action-fold

Weekly Downloads

2

Version

0.1.1

License

ISC

Unpacked Size

2.51 kB

Total Files

5

Last publish

Collaborators

  • mwillhite