Compare commits

..

3 Commits

Author SHA1 Message Date
hypercross 9ed23295ae build: include samples in prepare script 2026-04-28 16:52:03 +08:00
hypercross ca86bfc427 refactor: use effect for assignSelector in BaseGameClient
Replace subscribe with effect in assignSelector to ensure the
selector value is tracked and the callback is executed within
the reactive context.
2026-04-28 15:50:00 +08:00
hypercross 09c3fc443b feat(core): wrap prompt middleware in try-finally block
Ensure the prompt status is cleared even if the middleware chain
throws an error.
2026-04-28 15:29:08 +08:00
2 changed files with 18 additions and 13 deletions

View File

@ -18,7 +18,7 @@
"scripts": { "scripts": {
"build": "tsup", "build": "tsup",
"build:samples": "tsup --config tsup.samples.config.ts", "build:samples": "tsup --config tsup.samples.config.ts",
"prepare": "npm run build", "prepare": "npm run build && npm run build:samples",
"test": "vitest", "test": "vitest",
"test:run": "vitest run", "test:run": "vitest run",
"typecheck": "tsc --noEmit" "typecheck": "tsc --noEmit"

View File

@ -60,7 +60,9 @@ export abstract class BaseGameClient<
assignSelector<S>(selector: (t: T) => S, callback: (s: S) => void) { assignSelector<S>(selector: (t: T) => S, callback: (s: S) => void) {
const selected = computed(() => selector(this._context.value)); const selected = computed(() => selector(this._context.value));
return selected.subscribe(callback); return effect(() => {
callback(selected.value);
});
} }
addInterruption() { addInterruption() {
@ -87,17 +89,20 @@ export abstract class BaseGameClient<
} }
} }
try {
callback({ callback({
hasPrompt: true, hasPrompt: true,
player: ctx.player || "global", player: ctx.player || "global",
def: ctx.def, def: ctx.def,
tryAnswer, tryAnswer,
}); });
await next(); return await next();
} finally {
callback({ callback({
hasPrompt: false, hasPrompt: false,
player: ctx.player || "global", player: ctx.player || "global",
}); });
}
}); });
} }
selectStatus(callback: (status: ClientStatus) => void) { selectStatus(callback: (status: ClientStatus) => void) {