Skip to content

Commit d251f4a

Browse files
committed
set phase to null instead of empty string
1 parent 9c6f55d commit d251f4a

6 files changed

Lines changed: 33 additions & 29 deletions

File tree

src/client/client.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,13 @@ describe('log handling', () => {
439439
{
440440
action: makeMove('A', [], '0'),
441441
_stateID: 0,
442-
phase: '',
442+
phase: null,
443443
turn: 1,
444444
},
445445
{
446446
action: makeMove('A', [], '0'),
447447
_stateID: 1,
448-
phase: '',
448+
phase: null,
449449
turn: 1,
450450
},
451451
]);

src/client/log/log.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const PhaseMarker = props => {
109109
};
110110

111111
PhaseMarker.propTypes = {
112-
phase: PropTypes.string.isRequired,
112+
phase: PropTypes.string,
113113
numEvents: PropTypes.number.isRequired,
114114
};
115115

src/core/flow.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export function Flow({ moves, phases, endIf, turn, events, plugins }) {
226226

227227
let moveMap = {};
228228
let moveNames = new Set();
229-
let startingPhase = '';
229+
let startingPhase = null;
230230

231231
Object.keys(moves).forEach(name => moveNames.add(name));
232232

@@ -294,7 +294,7 @@ export function Flow({ moves, phases, endIf, turn, events, plugins }) {
294294
}
295295

296296
function GetPhase(ctx) {
297-
return phaseMap[ctx.phase];
297+
return ctx.phase ? phaseMap[ctx.phase] : phaseMap[''];
298298
}
299299

300300
function OnMove(s) {
@@ -555,21 +555,21 @@ export function Flow({ moves, phases, endIf, turn, events, plugins }) {
555555
return state;
556556
}
557557

558-
// If we aren't in a phase, there is nothing to do.
559-
// if (ctx.phase === '') {
560-
// return state;
561-
// }
558+
if (next) {
559+
next.push({ fn: UpdatePhase, arg, phase: ctx.phase });
560+
}
561+
562+
// If we aren't in a phase, there is nothing else to do.
563+
if (ctx.phase === null) {
564+
return state;
565+
}
562566

563567
// Run any cleanup code for the phase that is about to end.
564568
const conf = GetPhase(ctx);
565569
G = conf.onEnd(G, ctx);
566570

567-
if (next) {
568-
next.push({ fn: UpdatePhase, arg, phase: ctx.phase });
569-
}
570-
571571
// Reset the phase.
572-
ctx = { ...ctx, phase: '', playOrderPos: 0 };
572+
ctx = { ...ctx, phase: null, playOrderPos: 0 };
573573

574574
// Add log entry.
575575
const action = gameEvent('endPhase', arg);

src/core/flow.test.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ test('init', () => {
269269
expect(state.G).toMatchObject({ done: true });
270270
});
271271

272-
test('endIf', () => {
273-
{
272+
describe('endIf', () => {
273+
test('basic', () => {
274274
const flow = Flow({ endIf: G => G.win });
275275

276276
let state = flow.init({ G: {}, ctx: flow.ctx(2) });
@@ -288,14 +288,18 @@ test('endIf', () => {
288288
const t = flow.processMove(state, makeMove('move').payload);
289289
expect(t.ctx.gameover).toBe('A');
290290
}
291-
}
291+
});
292292

293-
// Test that the phase automatically ends.
294-
{
293+
test('phase automatically ends', () => {
295294
const game = {
296-
moves: {
297-
A: () => ({ win: 'A' }),
298-
B: G => G,
295+
phases: {
296+
A: {
297+
start: true,
298+
moves: {
299+
A: () => ({ win: 'A' }),
300+
B: G => G,
301+
},
302+
},
299303
},
300304
endIf: G => G.win,
301305
};
@@ -312,7 +316,7 @@ test('endIf', () => {
312316
client.getState().deltalog[client.getState().deltalog.length - 1].action
313317
.payload.type
314318
).toBe('endPhase');
315-
}
319+
});
316320
});
317321

318322
describe('turn.endIf', () => {
@@ -448,7 +452,7 @@ describe('endTurn / endPhase args', () => {
448452
let t = state;
449453
t = flow.processGameEvent(t, gameEvent('endPhase', 'C'));
450454
expect(error).toBeCalledWith(`invalid argument to endPhase: C`);
451-
expect(t.ctx.phase).toBe('');
455+
expect(t.ctx.phase).toBe(null);
452456
});
453457

454458
test('invalid arg to endTurn', () => {

src/core/reducer.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ test('deltalog', () => {
208208
{
209209
action: actionA,
210210
_stateID: 0,
211-
phase: '',
211+
phase: null,
212212
turn: 1,
213213
},
214214
]);
@@ -217,7 +217,7 @@ test('deltalog', () => {
217217
{
218218
action: actionB,
219219
_stateID: 1,
220-
phase: '',
220+
phase: null,
221221
turn: 1,
222222
},
223223
]);
@@ -226,7 +226,7 @@ test('deltalog', () => {
226226
{
227227
action: actionC,
228228
_stateID: 2,
229-
phase: '',
229+
phase: null,
230230
turn: 1,
231231
},
232232
]);

src/master/master.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe('update', () => {
117117
currentPlayer: '0',
118118
currentPlayerMoves: 0,
119119
numPlayers: 2,
120-
phase: '',
120+
phase: null,
121121
playOrder: ['0', '1'],
122122
playOrderPos: 0,
123123
turn: 1,
@@ -131,7 +131,7 @@ describe('update', () => {
131131
currentPlayer: '1',
132132
currentPlayerMoves: 0,
133133
numPlayers: 2,
134-
phase: '',
134+
phase: null,
135135
playOrder: ['0', '1'],
136136
playOrderPos: 1,
137137
turn: 2,

0 commit comments

Comments
 (0)