JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//cdn.jsdelivr.net/mithril/0.1.15/mithril.min.js"></script>
JavaScript
var converter = function(temperature) {
return [
m("input[type=number]", {
oninput: m.withAttr("value", temperature.setCelsius),
value: temperature.celsius
}),
"°C ⇄",
m("input[type=number]", {
oninput: m.withAttr("value", temperature.setFahrenheit),
value: temperature.fahrenheit
}),
"°F"
]
}
var Temperature = function() {
this.setCelsius = function(c) {
this.celsius = c
this.fahrenheit = Math.round((9/5 * c + 32) * 100) / 100;
}.bind(this)
this.setFahrenheit = function(f) {
this.fahrenheit = f
this.celsius = Math.round((5/9 * (f - 32)) * 100) / 100;
}.bind(this)
this.setCelsius(0)
}
m.module(document.body, {controller: Temperature, view: converter})