Skip to content

Commit 32dd6d9

Browse files
author
Roman Babaev
committed
Make cells array immutable
1 parent d80a2fa commit 32dd6d9

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Arena/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import "./styles.css";
66
const b = b_.lock("Arena");
77
const cellSize = 28;
88

9-
export class Arena extends React.Component {
9+
export class Arena extends React.PureComponent {
1010
static defaultProps = { zoom: 1 };
1111

1212
state = {

src/core/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@ export class Minesweeper {
9393
this.openedCells++;
9494
});
9595

96+
this.cells = [...this.cells];
97+
9698
const restCells = this.cells
9799
.map((cell, i) => (cell & CELL_OPENED) ? null : i)
98100
.filter(cell => cell !== null);
99101

100102
if (arraysCompare(this.minedCells, restCells)) {
101-
102103
this.gameState = 'won';
103104
this.flaggingMode = false;
104105
this.stopTimer();
@@ -129,6 +130,7 @@ export class Minesweeper {
129130
const cell = this.cells[i];
130131
if (!(cell & CELL_OPENED)) {
131132
this.cells[i] = toggleCellFlag(cell);
133+
this.cells = [...this.cells];
132134
(this.cells[i] & CELL_FLAGGED) ? this.flaggedCells++ : this.flaggedCells--;
133135
}
134136
this._render();

0 commit comments

Comments
 (0)