@@ -9,21 +9,20 @@ object ExperimentExamples {
99
1010 /**
1111 * This is the typical React timer example, modified to use OnUnmount.
12+ * (Also removed State in favour of just using Long directly.)
1213 */
1314 object OnUnmountExample {
1415
15- case class State (secondsElapsed : Long )
16-
1716 class Backend extends OnUnmount { // Extends OnUnmount
1817 // Removed `var interval`
19- def tick (scope : ComponentScopeM [_, State , _]): js.Function =
20- () => scope.modState(s => State (s.secondsElapsed + 1 ) )
18+ def tick (scope : ComponentScopeM [_, Long , _]): js.Function =
19+ () => scope.modState(_ + 1 )
2120 }
2221
2322 val Timer = ReactComponentB [Unit ](" Timer" )
24- .initialState(State ( 0 ) )
23+ .initialState(0L )
2524 .backend(_ => new Backend )
26- .render((_,S ,_) => div(" Seconds elapsed: " , S .secondsElapsed ))
25+ .render((_,s ,_) => div(" Seconds elapsed: " , s ))
2726 .componentDidMount(scope => {
2827 val i = window.setInterval(scope.backend.tick(scope), 1000 )
2928 scope.backend onUnmount window.clearInterval(i) // Use onUnmount here
@@ -37,14 +36,14 @@ object ExperimentExamples {
3736
3837 /**
3938 * This is the typical React timer example, modified to use SetInterval.
40- * Also removed State in favour of just using Long directly.
39+ * ( Also removed State in favour of just using Long directly.)
4140 */
4241 object SetIntervalExample {
4342
4443 class Backend extends SetInterval
4544
4645 val Timer = ReactComponentB [Unit ](" Timer" )
47- .initialState(0 )
46+ .initialState(0L )
4847 .backend(_ => new Backend )
4948 .render((_,s,_) => div(" Seconds elapsed: " , s))
5049 .componentDidMount(c => c.backend.setInterval(c.modState(_ + 1 ), 1000 ))
0 commit comments