Created
March 17, 2017 14:17
-
-
Save nickbalestra/56f607063b0c6810b656c8373f661b65 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import xs from 'xstream'; | |
const model = action$ => { | |
const reducer = (state = 0, action) => { | |
switch(action.type) { | |
case 'INCREASE': | |
return state + 1 | |
case 'DECREASE': | |
return state - 1 | |
default: | |
return state | |
} | |
} | |
return action$ | |
.startWith({ type: '@@INIT' }) | |
.fold(reducer) | |
} | |
const intent = sources => { | |
const increase$ = sources.DOM | |
.select('.increase') | |
.events('click') | |
.mapTo({type: 'INCREASE'}) | |
const decrease$ = sources.DOM | |
.select('.decrease') | |
.events('click') | |
.mapTo({type: 'DECREASE'}) | |
return xs.merge(increase$, decrease$) | |
} | |
const view = state$ => state$.map(total => ( | |
<div> | |
<h1>{ total }</h1> | |
<button className="increase">+</button> | |
<button className="decrease">-</button> | |
</div> | |
)) | |
export default function dialogue (sources) { | |
return { | |
DOM: view(model(intent(sources))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool stuff!