Created
January 4, 2017 00:10
-
-
Save andersonleite/300b51a3abdd67733ec99e443261d087 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
const {div, input, label, h2, makeDOMDriver} = CycleDOM; | |
function main(sources) { | |
const changeWeight$ = sources.DOM.select('.weight').events('input') | |
.map(ev => ev.target.value); | |
const changeHeight$ = sources.DOM.select('.height').events('input') | |
.map(ev => ev.target.value); | |
const state$ = Rx.Observable.combineLatest( | |
changeWeight$.startWith(70), | |
changeHeight$.startWith(170), | |
(weight, height) => { | |
const heightMeters = height * 0.01; | |
const bmi = Math.round(weight / (heightMeters * heightMeters)); | |
return {bmi, weight, height}; | |
} | |
) | |
return { | |
DOM: state$.map(state => | |
div([ | |
div([ | |
label('Weigth: ' + state.weight + 'kg'), | |
input('.weight', {type: 'range', min: 40, max: 150, value:state.weight}) | |
]), | |
div([ | |
label('Heigth: ' + state.height + 'cm'), | |
input('.height', {type: 'range', min: 140, max: 220, value: state.height}) | |
]), | |
h2('BMI is ' + state.bmi) | |
]) | |
) | |
}; | |
} | |
const drivers = { | |
DOM: makeDOMDriver('#app') | |
}; | |
Cycle.run(main, drivers); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment