Skip to content

Instantly share code, notes, and snippets.

@nickbalestra
Created March 17, 2017 14:17
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 nickbalestra/56f607063b0c6810b656c8373f661b65 to your computer and use it in GitHub Desktop.
Save nickbalestra/56f607063b0c6810b656c8373f661b65 to your computer and use it in GitHub Desktop.
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)))
}
}
@giodegiorgi
Copy link

cool stuff!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment