@@ -6,8 +6,8 @@ type Field {
66}
77
88component Main {
9- state celsius : Field = Field .Initial ("" )
109 state fahrenheit : Field = Field .Initial ("" )
10+ state celsius : Field = Field .Initial ("" )
1111
1212 style root {
1313 white-space : nowrap ;
@@ -25,14 +25,12 @@ component Main {
2525 }
2626
2727 fun toFahrenheit (value : String ) {
28- Number .fromString (value )
29- |> Maybe .map (
28+ Maybe .map (Number .fromString (value ),
3029 (celsius : Number ) { {celsius , Math .round (celsius * (9 / 5 ) + 32 )} })
3130 }
3231
3332 fun toCelsius (value : String ) {
34- Number .fromString (value )
35- |> Maybe .map (
33+ Maybe .map (Number .fromString (value ),
3634 (fahrenheit : Number ) {
3735 {fahrenheit , Math .round ((fahrenheit - 32 ) * (5 / 9 ))}
3836 })
@@ -56,19 +54,15 @@ component Main {
5654
5755 if String .isEmpty (cleaned ) {
5856 next { celsius : Field .Initial (value ) }
57+ } else if let Just ({celsius , fahrenheit }) = toFahrenheit (cleaned ) {
58+ next {
59+ fahrenheit : Field .Valid (Number .toString (fahrenheit )),
60+ celsius : Field .Valid (Number .toString (celsius ))
61+ }
5962 } else {
60- case toFahrenheit (cleaned ) {
61- Just ({celsius , fahrenheit }) =>
62- next {
63- fahrenheit : Field .Valid (Number .toString (fahrenheit )),
64- celsius : Field .Valid (Number .toString (celsius ))
65- }
66-
67- =>
68- next {
69- fahrenheit : Field .OutOfSync (getValue (fahrenheit )),
70- celsius : Field .Invalid (cleaned )
71- }
63+ next {
64+ fahrenheit : Field .OutOfSync (getValue (fahrenheit )),
65+ celsius : Field .Invalid (cleaned )
7266 }
7367 }
7468 }
@@ -82,19 +76,15 @@ component Main {
8276
8377 if String .isEmpty (cleaned ) {
8478 next { fahrenheit : Field .Initial (value ) }
79+ } else if let Just ({fahrenheit , celsius }) = toCelsius (cleaned ) {
80+ next {
81+ fahrenheit : Field .Valid (Number .toString (fahrenheit )),
82+ celsius : Field .Valid (Number .toString (celsius ))
83+ }
8584 } else {
86- case toCelsius (cleaned ) {
87- Just ({fahrenheit , celsius }) =>
88- next {
89- fahrenheit : Field .Valid (Number .toString (fahrenheit )),
90- celsius : Field .Valid (Number .toString (celsius ))
91- }
92-
93- =>
94- next {
95- celsius : Field .OutOfSync (getValue (celsius )),
96- fahrenheit : Field .Invalid (cleaned )
97- }
85+ next {
86+ celsius : Field .OutOfSync (getValue (celsius )),
87+ fahrenheit : Field .Invalid (cleaned )
9888 }
9989 }
10090 }
0 commit comments