updatge
This commit is contained in:
@@ -1,17 +1,22 @@
|
||||
import { onMounted, onServerPrefetch, useSSRContext, shallowRef, type ShallowRef } from 'vue';
|
||||
import { onMounted, onServerPrefetch, type ShallowRef, shallowRef } from "vue";
|
||||
import useDJSSRContext from "@/useDJSSRContext.ts";
|
||||
|
||||
declare global {
|
||||
// deno-lint-ignore no-var
|
||||
var appstate: Partial<Record<string, unknown>>;
|
||||
}
|
||||
|
||||
export default function useAsyncState<T>(key: string, getter: (context: { hostUrl: string }) => Promise<T | null>, options?: { suspensible: boolean }): { result: ShallowRef<T | null>, stateIsReady: Promise<unknown> } {
|
||||
const ssrContext = useSSRContext<{ registry: Record<string, unknown> }>();
|
||||
const isClient = typeof ssrContext === 'undefined';
|
||||
export default function useAsyncState<T>(
|
||||
key: string,
|
||||
getter: (context: { hostUrl: string }) => Promise<T | null>,
|
||||
options?: { suspensible: boolean },
|
||||
): { result: ShallowRef<T | null>; stateIsReady: Promise<unknown> } {
|
||||
const ssrContext = useDJSSRContext();
|
||||
const isClient = typeof ssrContext === "undefined";
|
||||
|
||||
const registry = ssrContext?.registry ?? globalThis?.appstate;
|
||||
|
||||
const hostUrl = isClient ? globalThis.location.origin : 'http://localhost:8080';
|
||||
const hostUrl = isClient ? globalThis.location.origin : "http://localhost:8080";
|
||||
|
||||
const state = shallowRef<T | null>(null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user