From 6173d6ac2e7af4afce7f324b9f7042b331a822e1 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Mon, 19 Sep 2022 20:48:45 +0200 Subject: [PATCH] refactor(nc-gui): implement `useGlobalState` for `useGlobal` composable --- packages/nc-gui/composables/useGlobal/index.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/nc-gui/composables/useGlobal/index.ts b/packages/nc-gui/composables/useGlobal/index.ts index 4591ff46a0..3088dc9dad 100644 --- a/packages/nc-gui/composables/useGlobal/index.ts +++ b/packages/nc-gui/composables/useGlobal/index.ts @@ -2,7 +2,7 @@ import { useGlobalState } from './state' import { useGlobalActions } from './actions' import type { UseGlobalReturn } from './types' import { useGlobalGetters } from './getters' -import { useNuxtApp, watch } from '#imports' +import { createGlobalState, useNuxtApp, watch } from '#imports' /** * Global state is injected by {@link import('~/plugins/state') state} plugin into our nuxt app (available as `$state`). @@ -34,11 +34,8 @@ import { useNuxtApp, watch } from '#imports' * console.log(state.isLoading.value) // isLoading = true if any api request is still running * ``` */ -export const useGlobal = (): UseGlobalReturn => { - const { $state, provide } = useNuxtApp() - - /** If state already exists, return it */ - if (typeof $state !== 'undefined') return $state +export const useGlobal = createGlobalState((): UseGlobalReturn => { + const { provide } = useNuxtApp() const state = useGlobalState() @@ -84,4 +81,4 @@ export const useGlobal = (): UseGlobalReturn => { provide('state', globalState) return globalState -} +})