From f1cff0738a5e7504dc0d8c1c5fce299cbf5579dd Mon Sep 17 00:00:00 2001 From: QiroNT Date: Tue, 29 Nov 2022 20:01:05 +0800 Subject: [PATCH] chore: use pinia for command registry (#223) --- composables/command.ts | 14 +++----------- plugins/command.ts | 7 ------- 2 files changed, 3 insertions(+), 18 deletions(-) delete mode 100644 plugins/command.ts diff --git a/composables/command.ts b/composables/command.ts index 37d8b6d8..5ecccec1 100644 --- a/composables/command.ts +++ b/composables/command.ts @@ -1,4 +1,5 @@ import type { ComputedRef } from 'vue' +import { defineStore } from 'pinia' import Fuse from 'fuse.js' import type { LocaleObject } from '#i18n' @@ -54,7 +55,7 @@ export type QueryIndexedCommand = ResolvedCommand & { const r = (i: T | (() => T)): T => typeof i === 'function' ? i() : i -export const provideCommandRegistry = () => { +export const useCommandRegistry = defineStore('command', () => { const providers = reactive(new Set()) const commands = computed(() => @@ -165,16 +166,7 @@ export const provideCommandRegistry = () => { } }, } -} - -export const useCommandRegistry = () => { - const { $command } = useNuxtApp() - const registry = $command as ReturnType - if (!registry) - throw new Error('Command registry not found') - - return registry -} +}) export const useCommand = (cmd: CommandProvider) => { const registry = useCommandRegistry() diff --git a/plugins/command.ts b/plugins/command.ts deleted file mode 100644 index f92f4107..00000000 --- a/plugins/command.ts +++ /dev/null @@ -1,7 +0,0 @@ -export default defineNuxtPlugin(() => { - return { - provide: { - command: provideCommandRegistry(), - }, - } -})