diff --git a/packages-user/client-base/src/use/hotkey.ts b/packages-user/client-base/src/use/hotkey.ts index 944323c..75e7f71 100644 --- a/packages-user/client-base/src/use/hotkey.ts +++ b/packages-user/client-base/src/use/hotkey.ts @@ -1,6 +1,6 @@ import { IHotkeyEmitInfo, IHotkeySystem } from '@motajs/system'; import { IHotkeyUsing } from './types'; -import { getCurrentInstance, onMounted, onUnmounted } from 'vue'; +import { getCurrentInstance, onBeforeMount, onUnmounted } from 'vue'; import { logger } from '@motajs/common'; class HotkeyUsing implements IHotkeyUsing { @@ -21,7 +21,7 @@ class HotkeyUsing implements IHotkeyUsing { const { promise, resolve } = Promise.withResolvers(); this.scopePromise = promise; - onMounted(() => { + onBeforeMount(() => { this.mounted = true; const scope = system.enterScope(clearImpl); this.keyScope = scope; diff --git a/packages-user/client-modules/src/render/use.ts b/packages-user/client-modules/src/render/use.ts index 55b6aaa..81d7644 100644 --- a/packages-user/client-modules/src/render/use.ts +++ b/packages-user/client-modules/src/render/use.ts @@ -8,7 +8,6 @@ import { } from '@motajs/animate'; import { logger } from '@motajs/common'; import { IRenderItem, IRenderTreeRoot } from '@motajs/render'; -import { Hotkey, gameKey } from '@motajs/system'; import { ComponentInternalInstance, getCurrentInstance, @@ -64,30 +63,6 @@ export function onOrientationChange(hook: OrientationHook) { }); } -type KeyUsing = [Hotkey, symbol]; - -/** - * 在组件中定义按键操作 - * @param noScope 是否不创建新作用域 - * @param scope 指定作用域,如果 `noScope` 为 `true`,则此项无效 - */ -export function useKey(noScope: boolean = false, scope?: symbol): KeyUsing { - if (noScope) { - return [gameKey, gameKey.scope]; - } else { - const sym = scope ?? Symbol(); - if (sym === gameKey.scope) { - return [gameKey, gameKey.scope]; - } else { - gameKey.use(sym); - onUnmounted(() => { - gameKey.dispose(); - }); - return [gameKey, sym]; - } - } -} - export interface ITransitionedController { readonly ref: Ref; readonly value: T;