Skip to content

Commit

Permalink
fix: Prevent TypeError: state.deltalog is not iterable (#888)
Browse files Browse the repository at this point in the history
* Prevent TypeError: state.deltalog is not iterable

#788 "UnhandledPromiseRejectionWarning: TypeError: state.deltalog is not iterable"

Everywhere else that deltalog is updated, it uses this (state.deltalog || []) pattern.

* test(core): Add test for endIf during game initialization with phases

Co-authored-by: delucis <swithinbank@gmail.com>
  • Loading branch information
mdzw and delucis authored Jan 15, 2021
1 parent c178a41 commit 3b8ac79
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/core/flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,20 @@ describe('endIf', () => {
.payload.type
).toBe('endPhase');
});

test('during game initialization with phases', () => {
const flow = Flow({
phases: {
A: {
start: true,
},
},
endIf: () => 'gameover',
});

const state = flow.init({ G: {}, ctx: flow.ctx(2) } as State);
expect(state.ctx.gameover).toBe('gameover');
});
});

test('isPlayerActive', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export function Flow({
logEntry.automatic = true;
}

const deltalog = [...state.deltalog, logEntry];
const deltalog = [...(state.deltalog || []), logEntry];

return { ...state, G, ctx, deltalog };
}
Expand Down

0 comments on commit 3b8ac79

Please sign in to comment.