Skip to content

Instantly share code, notes, and snippets.

@yelouafi
Last active November 3, 2015 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yelouafi/5d9f6516c5c119818972 to your computer and use it in GitHub Desktop.
Save yelouafi/5d9f6516c5c119818972 to your computer and use it in GitHub Desktop.
/** @jsx html */
import { html } from 'snabbdom-jsx';
import Type from 'union-type';
const Action = Type({
Increment : [],
Decrement : [],
});
const view = ({state, dispatch}) =>
<div>
<button on-click={ [dispatch, Action.Increment()] }>+</button>
<button on-click={ [dispatch, Action.Decrement()] }>-</button>
<div>Count : {state}</div>
</div>;
// returns the initial state
function init() { return 0; }
// updates the state
function update(state, action) {
return Action.case({
Increment : () => state + 1,
Decrement : () => state - 1,
}, action);
}
export default { init, view, update, Action };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment