mirror of
https://github.com/motajs/template.git
synced 2026-10-29 20:30:20 +08:00
chore: Hotkey 系统遗留提交
This commit is contained in:
parent
21dea3adf0
commit
4115753f1f
@ -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<symbol>();
|
||||
this.scopePromise = promise;
|
||||
|
||||
onMounted(() => {
|
||||
onBeforeMount(() => {
|
||||
this.mounted = true;
|
||||
const scope = system.enterScope(clearImpl);
|
||||
this.keyScope = scope;
|
||||
|
||||
@ -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<T> {
|
||||
readonly ref: Ref<T>;
|
||||
readonly value: T;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user