Skip to content

Commit

Permalink
[Game] removed DEFAULT_STATE
Browse files Browse the repository at this point in the history
It was a bit concerning having to deal with worrying about mutations, so I decided to just write out the stuff two-ish times. My concerns were along the lines of, e.g. microsoft/TypeScript#10725 , and as a side note, it's a bit annoying that I have to worry about mutating prevState in this.setState.
  • Loading branch information
swpease committed Jul 1, 2018
1 parent 5535b52 commit a2e3dda
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/Game/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ interface State {
playerToggleKey: number,
};

const DEFAULT_STATE: State = {
interface Props extends WithStyles<typeof styles> { };

class Game extends React.Component<Props, State> {
constructor(props: Props) {
super(props);

this.state = {
playerType: "player",
turn: "red",
winner: "",
Expand All @@ -79,15 +85,7 @@ const DEFAULT_STATE: State = {
},
groupedWords: [], // as GroupedWord[],
playerToggleKey: 0
};

interface Props extends WithStyles<typeof styles> { };

class Game extends React.Component<Props, State> {
constructor(props: Props) {
super(props);

this.state = DEFAULT_STATE;
};

this.togglePlayerType = this.togglePlayerType.bind(this);
this.endTurnHandler = this.endTurnHandler.bind(this);
Expand All @@ -100,8 +98,16 @@ class Game extends React.Component<Props, State> {
}

createNewGame() {
this.setState({ ...DEFAULT_STATE });
this.setState({ playerToggleKey: Math.random() }) // I just need this to change somehow.
this.setState({
playerType: "player",
turn: "red",
winner: "",
remaining: {
red: 9,
blue: 8
},
playerToggleKey: Math.random()
});

shuffle(WORDBANK);
const gameWords: string[] = WORDBANK.slice(0, 25);
Expand Down

0 comments on commit a2e3dda

Please sign in to comment.