bfd680490f
#69 added `useAppContext()` as a Vue-native rename of Ink's `useApp()`, qualified to avoid reading as the Vue application instance. On reflection the "Context" suffix borrowed the name of an internal grab-bag context and slightly mislabels the hook — it returns app lifecycle controls, not that context. The collision worry doesn't hold up: Vue has no `useApp()`, the returned `{ exit, waitUntilRenderFlush }` is clearly not the Vue app instance, and "App" in vue-tui already means the `TuiApp` from `createApp()`. Rename to `useApp()` for full Ink fidelity (same name + same shape), and drop the now-defunct "App composable" entry from ink-divergences.md — it ceases to be a divergence. Internal context cleanup (the grab-bag `AppContext` + the `StdinContext` duplication) is intentionally out of scope here, tracked separately. BREAKING CHANGE: `useAppContext()` is renamed to `useApp()`. Replace `const { exit } = useAppContext()` with `const { exit } = useApp()`. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
33 lines
680 B
TypeScript
33 lines
680 B
TypeScript
import { createApp, Text, useApp } from "@vue-tui/runtime";
|
|
import { defineComponent, onMounted, onScopeDispose, shallowRef } from "vue";
|
|
|
|
const App = defineComponent(() => {
|
|
const counter = shallowRef(0);
|
|
const { exit } = useApp();
|
|
|
|
onMounted(() => {
|
|
setTimeout(() => {
|
|
exit(new Error("errored"));
|
|
}, 500);
|
|
|
|
const timer = setInterval(() => {
|
|
counter.value++;
|
|
}, 100);
|
|
|
|
onScopeDispose(() => {
|
|
clearInterval(timer);
|
|
});
|
|
});
|
|
|
|
return () => <Text>Counter: {counter.value}</Text>;
|
|
});
|
|
|
|
const app = createApp(App);
|
|
app.mount();
|
|
|
|
try {
|
|
await app.waitUntilExit();
|
|
} catch (error: unknown) {
|
|
console.log((error as Error).message);
|
|
}
|