feat(vue-runtime-help): app不存在时抛异常,保证app一定存在,避免多余的可选链

This commit is contained in:
roymondchen 2025-04-23 15:05:14 +08:00
parent e7e9197ae3
commit fd7e737e8c
2 changed files with 7 additions and 3 deletions

View File

@ -1,5 +1,5 @@
{
"version": "1.1.1",
"version": "1.1.2",
"name": "@tmagic/vue-runtime-help",
"type": "module",
"sideEffects": false,

View File

@ -65,13 +65,17 @@ export const registerNodeHooks = (node?: TMagicNode, methods: Methods = {}) => {
};
export const useApp = <T extends TMagicApp = TMagicApp>({
methods = {},
methods,
config,
iteratorContainerId,
iteratorIndex,
}: UseAppOptions) => {
const app = inject<T>('app');
if (!app) {
throw new Error(`component ${config.type}: app is not injected`);
}
const node = useNode(
{
config,
@ -81,7 +85,7 @@ export const useApp = <T extends TMagicApp = TMagicApp>({
app,
);
if (node) {
if (node && methods) {
registerNodeHooks(node, methods);
}