|
|
@ -2,7 +2,7 @@ import { useGlobalState } from './state' |
|
|
|
import { useGlobalActions } from './actions' |
|
|
|
import { useGlobalActions } from './actions' |
|
|
|
import type { UseGlobalReturn } from './types' |
|
|
|
import type { UseGlobalReturn } from './types' |
|
|
|
import { useGlobalGetters } from './getters' |
|
|
|
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`). |
|
|
|
* 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
|
|
|
|
* console.log(state.isLoading.value) // isLoading = true if any api request is still running
|
|
|
|
* ``` |
|
|
|
* ``` |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
export const useGlobal = (): UseGlobalReturn => { |
|
|
|
export const useGlobal = createGlobalState((): UseGlobalReturn => { |
|
|
|
const { $state, provide } = useNuxtApp() |
|
|
|
const { provide } = useNuxtApp() |
|
|
|
|
|
|
|
|
|
|
|
/** If state already exists, return it */ |
|
|
|
|
|
|
|
if (typeof $state !== 'undefined') return $state |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const state = useGlobalState() |
|
|
|
const state = useGlobalState() |
|
|
|
|
|
|
|
|
|
|
@ -84,4 +81,4 @@ export const useGlobal = (): UseGlobalReturn => { |
|
|
|
provide('state', globalState) |
|
|
|
provide('state', globalState) |
|
|
|
|
|
|
|
|
|
|
|
return globalState |
|
|
|
return globalState |
|
|
|
} |
|
|
|
}) |
|
|
|