@@ -8,32 +8,42 @@ class Board extends Component {
8
8
[ "." , "." , "O" ] ,
9
9
[ "O" , "." , "." ] ,
10
10
[ "." , "X" , "." ] ,
11
- ] )
11
+ ] ) ;
12
+
13
+ this . winner = this . createDerived ( ( ) => {
14
+ return "." ;
15
+ } , [ this . board ] )
12
16
13
17
setTimeout ( ( ) => {
14
18
// Set the board to any value and observe the change!
15
19
this . board . setValue ( [
16
20
[ "." , "O" , "O" ] ,
17
21
[ "O" , "X" , "X" ] ,
18
22
[ "X" , "X" , "." , "." ] ,
23
+ [ "." ]
19
24
] )
20
25
} , 1000 )
21
26
}
22
27
28
+ playTurn ( rowIdx , colIdx ) {
29
+ // some logic
30
+ }
31
+
23
32
render ( ) {
24
33
const containerProps = { style : "display: flex; flex-direction: column" } ;
25
34
const rowProps = { style : "display: flex" } ;
26
35
const cellProps = { style : "border: 1px solid black; width: 20px; height: 20px;" } ;
27
36
28
- return this . element ( "div" , containerProps , [
29
- this . map ( this . board , { } , function ( row ) {
30
- return this . element ( "div" , rowProps , [
31
- this . map ( row , { } , function ( cell ) {
32
- const isOccupied = this . createDerived ( ( ) => cell . value !== "." , [ cell ] ) ;
37
+ const play_turn_binded = this . playTurn . bind ( this ) ;
33
38
34
- return this . element ( "div" , cellProps , [
35
- this . condition ( isOccupied , { } , function ( ) {
36
- return this . element ( "div" , { textContent : cell } )
39
+ return this . div ( containerProps , [
40
+ this . map ( this . board , function ( row , rowIdx ) {
41
+ return this . div ( rowProps , [
42
+ this . map ( row , { } , function ( cell , colIdx ) {
43
+ return this . div ( cellProps , [
44
+ this . div ( {
45
+ textContent : cell ,
46
+ onclick : ( ) => play_turn_binded ( rowIdx , colIdx )
37
47
} )
38
48
] ) ;
39
49
} )
0 commit comments