Created
May 5, 2017 18:31
-
-
Save jayrbolton/b38dfe8f2d8830dc01da0824f8598be1 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
function model({ fahrenInput, celsiusInput }) { | |
const fahrenChange = fahrenInput.map((ev) => ev.currentTarget.value); | |
const celsiusChange = celsiusInput.map((ev) => ev.currentTarget.value); | |
const fahrenToCelsius = | |
fahrenChange.map(parseFloat).filter((n) => !isNaN(n)).map((f) => (f - 32) / 1.8); | |
const celsiusToFahren = | |
celsiusChange.map(parseFloat).filter((n) => !isNaN(n)).map((c) => c * 9 / 5 + 32); | |
const celsius = stepper(0, combine(celsiusChange, fahrenToCelsius)); | |
const fahren = stepper(0, combine(fahrenChange, celsiusToFahren)); | |
return Now.of([{ fahren, celsius }, []]); | |
} | |
const view = ({ fahren, celsius }) => div([ | |
div([ | |
label("Fahrenheit"), | |
input({ props: { value: fahren }, output: { fahrenInput: "input" } }) | |
]), | |
div([ | |
label("Celsius"), | |
input({ props: { value: celsius }, output: { celsiusInput: "input" } }) | |
]) | |
]); | |
const component = modelView(model, view); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment