Skip to content

Instantly share code, notes, and snippets.

@jayrbolton
Created May 5, 2017 18:31
Show Gist options
  • Save jayrbolton/b38dfe8f2d8830dc01da0824f8598be1 to your computer and use it in GitHub Desktop.
Save jayrbolton/b38dfe8f2d8830dc01da0824f8598be1 to your computer and use it in GitHub Desktop.
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