Skip to content

Commit

Permalink
refactor: Clean up after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis committed Aug 6, 2021
1 parent f9356bc commit 8bc458e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
34 changes: 17 additions & 17 deletions src/core/flow.test.ts
Expand Up @@ -489,11 +489,11 @@ describe('stages', () => {
stages: {
A: {
moves: {
leaveStage: (G, ctx) => void ctx.events.endStage(),
leaveStage: ({ events }) => void events.endStage(),
},
},
},
endIf: (G, ctx) => ctx.activePlayers === null,
endIf: ({ ctx }) => ctx.activePlayers === null,
},
},
});
Expand Down Expand Up @@ -524,7 +524,7 @@ describe('stages', () => {
currentPlayer: 'A',
moveLimit: 1,
},
endIf: (G, ctx) => ctx.activePlayers === null,
endIf: ({ ctx }) => ctx.activePlayers === null,
stages: {
A: {
moves: {
Expand Down Expand Up @@ -1170,10 +1170,10 @@ describe('events in hooks', () => {
};

describe('endTurn', () => {
const conditionalEndTurn = (G, ctx) => {
const conditionalEndTurn = ({ G, events }) => {
if (!G.shouldEnd) return;
G.shouldEnd = false;
ctx.events.endTurn();
events.endTurn();
};

test('can end turn from turn.onBegin', () => {
Expand Down Expand Up @@ -1290,10 +1290,10 @@ describe('events in hooks', () => {
});

describe('endPhase', () => {
const conditionalEndPhase = (G, ctx) => {
const conditionalEndPhase = ({ G, events }) => {
if (!G.shouldEnd) return;
G.shouldEnd = false;
ctx.events.endPhase();
events.endPhase();
};

test('can end phase from turn.onBegin', () => {
Expand Down Expand Up @@ -1466,7 +1466,7 @@ test('events in hooks triggered by moves should be processed', () => {
});

test('stage events should not be processed out of turn', () => {
const game = {
const game: Game = {
phases: {
A: {
start: true,
Expand All @@ -1477,15 +1477,15 @@ test('stage events should not be processed out of turn', () => {
stages: {
A1: {
moves: {
endStage: (G, ctx) => {
endStage: ({ G, events }) => {
G.endStage = true;
ctx.events.endStage();
events.endStage();
},
},
},
},
},
endIf: (G) => G.endStage,
endIf: ({ G }) => G.endStage,
next: 'B',
},
B: {
Expand Down Expand Up @@ -1531,16 +1531,16 @@ describe('hook execution order', () => {
game: {
moves: {
move: () => void calls.push('move'),
setStage: (G, ctx) => {
ctx.events.setStage('A');
setStage: ({ events }) => {
events.setStage('A');
calls.push('moves.setStage');
},
endStage: (G, ctx) => {
ctx.events.endStage();
endStage: ({ events }) => {
events.endStage();
calls.push('moves.endStage');
},
setActivePlayers: (G, ctx) => {
ctx.events.setActivePlayers({ all: 'A', moveLimit: 1 });
setActivePlayers: ({ events }) => {
events.setActivePlayers({ all: 'A', moveLimit: 1 });
calls.push('moves.setActivePlayers');
},
},
Expand Down
9 changes: 4 additions & 5 deletions src/plugins/plugin-events.ts
Expand Up @@ -24,11 +24,10 @@ const EventsPlugin: Plugin<EventsAPI & PrivateEventsAPI> = {
// endings to dispatch the current turn and phase correctly.
fnWrap:
(fn) =>
(G, ctx, ...args) => {
const api = ctx.events as PrivateEventsAPI;
if (api) api._obj.updateTurnContext(ctx);
G = fn(G, ctx, ...args);
return G;
(context, ...args) => {
const api = context.events as PrivateEventsAPI;
if (api) api._obj.updateTurnContext(context.ctx);
return fn(context, ...args);
},

dangerouslyFlushRawState: ({ state, api }) => api._obj.update(state),
Expand Down

0 comments on commit 8bc458e

Please sign in to comment.