Skip to content

Commit

Permalink
fix(mutators): handle nested mutators (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelauer committed Jun 26, 2024
2 parents c043065 + 1a4dbca commit b089304
Show file tree
Hide file tree
Showing 19 changed files with 282 additions and 104 deletions.
1 change: 0 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module.exports = {
parser: "@typescript-eslint/parser",
//ignorePatterns: ["*.js"],
parserOptions: {
project: [
"./.examples/tic-tac-toe/tsconfig.json",
Expand Down
185 changes: 185 additions & 0 deletions .examples/tic-tac-toe/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .examples/tic-tac-toe/src/app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import observeGameUpdates from "./observe-game-updates";

observeGameUpdates();

GameShip.mutate.Turn.nextTurn();
GameShip.mutate.Turn.nextTurn().catch(console.error);
8 changes: 3 additions & 5 deletions .examples/tic-tac-toe/src/app/observe-game-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ const log = getTheseusLogger("Observe");

export default function()
{
GameShip.observe((state) =>
{
onGameUpdated();

GameShip.observe(async (state) =>
{
switch (state.winner)
{
case "stalemate":
Expand All @@ -22,7 +20,7 @@ export default function()
break;
default:
log.major("Move detected! Taking next turn...");
GameShip.mutate.Turn.nextTurn();
await onGameUpdated();
break;
}
}, false);
Expand Down
8 changes: 6 additions & 2 deletions .examples/tic-tac-toe/src/app/on-game-updated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { GameShip } from "../game-ship/game-ship";

const log = getTheseusLogger("OnGameUpdated");

export const onGameUpdated = () =>
export const onGameUpdated = async () =>
{
const foundTriple = GameShip.refine.Outcome.checkForTriples();
if (foundTriple)
{
GameShip.evolve.Turn.setWinner("winner");
GameShip.mutate.Turn.setWinner("winner");
}
else
{
await GameShip.mutate.Turn.nextTurn();
}

const rendered = GameShip.refine.Render.renderToString();
Expand Down
Loading

0 comments on commit b089304

Please sign in to comment.