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": {
"build": "tsup",
"build:samples": "tsup --config tsup.samples.config.ts",
"prepare": "npm run build",
"prepare": "npm run build && npm run build:samples",
"test": "vitest",
"test:run": "vitest run",
"typecheck": "tsc --noEmit"

View File

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