Last active
November 3, 2015 09:53
-
-
Save yelouafi/5d9f6516c5c119818972 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @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