Skip to content

Commit 279a822

Browse files
committed
fix(flow): Pass correct ctx to onMove hooks
Addresses a regression introduced in #1019, which passed a stale version of `ctx` when calling `onMove` hooks. This was particularly noticeable if the move triggered the end of a player’s stage, which the `onMove` hook would then not see.
1 parent e3b2cb1 commit 279a822

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

src/core/flow.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -698,13 +698,12 @@ export function Flow({
698698

699699
function ProcessMove(state: State, action: ActionPayload.MakeMove): State {
700700
const { playerID, type } = action;
701-
const { ctx } = state;
702-
const { currentPlayer, activePlayers, _activePlayersMaxMoves } = ctx;
703-
const move = GetMove(ctx, type, playerID);
701+
const { currentPlayer, activePlayers, _activePlayersMaxMoves } = state.ctx;
702+
const move = GetMove(state.ctx, type, playerID);
704703
const shouldCount =
705704
!move || typeof move === 'function' || move.noLimit !== true;
706705

707-
let { numMoves, _activePlayersNumMoves } = ctx;
706+
let { numMoves, _activePlayersNumMoves } = state.ctx;
708707
if (shouldCount) {
709708
if (playerID === currentPlayer) numMoves++;
710709
if (activePlayers) _activePlayersNumMoves[playerID]++;
@@ -713,7 +712,7 @@ export function Flow({
713712
state = {
714713
...state,
715714
ctx: {
716-
...ctx,
715+
...state.ctx,
717716
numMoves,
718717
_activePlayersNumMoves,
719718
},
@@ -726,10 +725,10 @@ export function Flow({
726725
state = EndStage(state, { playerID, automatic: true });
727726
}
728727

729-
const phaseConfig = GetPhase(ctx);
728+
const phaseConfig = GetPhase(state.ctx);
730729
const G = phaseConfig.turn.wrapped.onMove({
731730
...state,
732-
ctx: { ...ctx, playerID },
731+
ctx: { ...state.ctx, playerID },
733732
});
734733
state = { ...state, G };
735734

0 commit comments

Comments
 (0)