Skip to content

Commit 9676e90

Browse files
committed
refactor: Update Adagrams proxy
The proxy will now pass through any implementations that aren't undefined
1 parent 82d05ff commit 9676e90

File tree

6 files changed

+30
-31
lines changed

6 files changed

+30
-31
lines changed

src/demo-react/adagrams-proxy.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,46 @@ const Real = {
1414

1515
const Proxy = {
1616
drawLetters() {
17-
const defaultLetters = ["H", "E", "L", "L", "O", "W", "O", "R", "L", "D"];
18-
19-
if (typeof Real.drawLetters === "function") {
20-
return Real.drawLetters() || defaultLetters;
17+
const real = Real.drawLetters();
18+
if (typeof real === 'undefined') {
19+
return ["H", "E", "L", "L", "O", "W", "O", "R", "L", "D"];
2120
}
2221

23-
return defaultLetters;
22+
return real;
2423
},
2524

2625
usesAvailableLetters(input, lettersInHand) {
27-
if (typeof Real.usesAvailableLetters === "function") {
28-
return Real.usesAvailableLetters(input, lettersInHand);
26+
const real = Real.usesAvailableLetters(input, lettersInHand);
27+
if (typeof real === 'undefined') {
28+
return true;
2929
}
3030

31-
return true;
31+
return real;
3232
},
3333

3434
scoreWord(word) {
35-
if (typeof Real.scoreWord === "function") {
36-
return Real.scoreWord(word);
35+
const real = Real.scoreWord(word);
36+
if (typeof real === 'undefined') {
37+
return 1;
3738
}
3839

39-
return 1;
40+
return real;
4041
},
4142

4243
highestScoreFrom(words) {
43-
if (typeof Real.highestScoreFrom === "function") {
44-
return Real.highestScoreFrom(words);
44+
const real = Real.highestScoreFrom(words);
45+
if (typeof real === 'undefined') {
46+
if (words.length < 1) {
47+
return {};
48+
}
49+
50+
return {
51+
word: words[0],
52+
score: Proxy.scoreWord(words[0]),
53+
};
4554
}
4655

47-
if (words.length < 1) return null;
48-
49-
return {
50-
word: words[0],
51-
score: Proxy.scoreWord(words[0]),
52-
};
56+
return real;
5357
},
5458
};
5559

src/demo-react/gamestate/reducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { validateGuessInput } from './rules';
77
import { ScreenId } from './screens';
88
import { timerMiddleware } from './timer';
99

10-
import Adagrams from 'demo-react/adagrams';
10+
import Adagrams from 'demo-react/adagrams-proxy';
1111

1212
const GO_STRAIGHT_TO_WIN = false;
1313

src/demo-react/gamestate/rules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as Actions from './action-types';
22
import { SetErrorAction } from './errors';
33

4-
import Adagrams from 'demo-react/adagrams';
4+
import Adagrams from 'demo-react/adagrams-proxy';
55

66
export function validateGuessInput(wrappedReducer) {
77
return (state, action) => {

src/demo-react/gamestate/screens.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,3 @@ export class SwitchScreenAction {
1515
this.payload = screenId;
1616
}
1717
}
18-
19-
export function onHelpScreen(state) {
20-
return state.currentScreen === ScreenId.HOW_TO;
21-
}
22-
23-
export function onSetupScreen(state) {
24-
return state.currentScreen === ScreenId.SETUP;
25-
}

src/demo-react/gamestate/win-selectors.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import Adagrams from 'demo-react/adagrams';
1+
import Adagrams from 'demo-react/adagrams-proxy';
22

33
export class WinScreenInfo {
4+
playerScores;
5+
roundWinners;
6+
47
constructor(state) {
58
this.playerScores = state.players.map(
69
player => {

src/demo-react/screens/game.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { GUESS } from '../gamestate/action-types';
99
import GameTimer from '../components/timer';
1010
import { useGameStateContext } from '../components/gamestate-context';
1111

12-
import Adagrams from 'demo-react/adagrams';
12+
import Adagrams from 'demo-react/adagrams-proxy';
1313

1414
export default function Game() {
1515
const { state } = useGameStateContext();

0 commit comments

Comments
 (0)