File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
react_learn/src/main/scala/tutorial/webapp Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -31,12 +31,13 @@ object Board {
31
31
32
32
case class State (
33
33
square: List [Option [String ]],
34
+ xIsNext: Boolean
34
35
)
35
36
36
37
class Backend (bs : BackendScope [Unit , State ]) {
37
38
38
39
def render (state : State ) = {
39
- val status = " Next player: X "
40
+ val status = " Next player: " + { if (state.xIsNext) " X " else " O " }
40
41
< .div(
41
42
< .div(
42
43
^ .cls := " status" ,
@@ -70,11 +71,16 @@ object Board {
70
71
)
71
72
}
72
73
73
- def handleClick (i : Int ) = bs.modState(s => s.copy(square= s.square.updated(i, Some (" X" ))))
74
+ def handleClick (i : Int ) = bs.modState(
75
+ s => s.copy(
76
+ square= s.square.updated(i, Some (if (s.xIsNext) " X" else " O" )),
77
+ xIsNext= ! s.xIsNext
78
+ )
79
+ )
74
80
}
75
81
76
82
val component = ScalaComponent .builder[Unit ](" Board" )
77
- .initialState(State (List .fill(9 )(None )))
83
+ .initialState(State (List .fill(9 )(None ), true ))
78
84
.renderBackend[Backend ]
79
85
.build
80
86
You can’t perform that action at this time.
0 commit comments