Skip to content

Commit acb9d8c

Browse files
committed
enable events API in initial onTurnBegin/onPhaseBegin
1 parent 5d3a34d commit acb9d8c

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/core/reducer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ export function CreateGameReducer({ game, numPlayers, multiplayer }) {
6767

6868
const state = game.flow.init({ G: initial.G, ctx: ctxWithAPI });
6969

70+
const { ctx: ctxWithEvents } = events.update(state);
7071
initial.G = state.G;
7172
initial._undo = state._undo;
72-
initial.ctx = random.update(state.ctx);
73+
initial.ctx = ctxWithEvents;
74+
initial.ctx = random.update(initial.ctx);
7375
initial.ctx = Random.detach(initial.ctx);
7476
initial.ctx = Events.detach(initial.ctx);
7577

src/core/reducer.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,22 @@ describe('Random inside setup()', () => {
250250
});
251251
});
252252

253+
test('events API inside first onTurnBegin', () => {
254+
const game = Game({
255+
flow: {
256+
setActionPlayers: true,
257+
onTurnBegin: (G, ctx) => {
258+
ctx.events.setActionPlayers(['0', '1']);
259+
},
260+
},
261+
});
262+
263+
const reducer = CreateGameReducer({ game });
264+
const state = reducer(undefined, { type: 'init' });
265+
266+
expect(state.ctx.actionPlayers).toEqual(['0', '1']);
267+
});
268+
253269
test('undo / redo', () => {
254270
let game = Game({
255271
moves: {

0 commit comments

Comments
 (0)