Skip to content

halfzebra/algebraic-actions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

algebraic-actions

A library that helps representing Redux Actions as an Algebraic Union Type in JavaScript.

In helps to describe state transitions in a type-safe manner with exhaustive Action coverage.

Usage

const Actions = withCase(fromObject({
  Increment: PropTypes.any,
  Decrement: PropTypes.any,
  DecrementBy: PropTypes.number
}));

const reducer = Actions.case({
  Increment: state => state + 1,
  Decrement: state => state - 1,
  DecrementBy: (state, number) => state - number,
  _: (state = 0) => state
});

const store = createStore(reducer);

store.dispatch(Actions.Increment())

Acknowledgements