Comparing version 0.0.6-dev.0 to 0.0.7-dev.0
@@ -6,3 +6,3 @@ import { ComputedRef, Ref } from 'vue'; | ||
interface FetchOptions<T> { | ||
serverPrefetch?: boolean; | ||
lazy?: boolean; | ||
initialFetch?: boolean; | ||
@@ -9,0 +9,0 @@ initialValue?: () => T; |
@@ -7,3 +7,3 @@ import { computed, toRef, reactive, watch, toRaw, onMounted, } from 'vue'; | ||
export function useFetch(key, hook, options) { | ||
const serverPrefetch = options?.serverPrefetch ?? true; | ||
const isLazy = options?.lazy ?? false; | ||
const initialFetch = options?.initialFetch ?? true; | ||
@@ -20,3 +20,3 @@ const initialValue = options?.initialValue; | ||
if (appContext.isClient) { | ||
if (serverPrefetch && appContext.state.hasOwnProperty(fetchKey)) { | ||
if (!isLazy && appContext.state.hasOwnProperty(fetchKey)) { | ||
initialState = appContext.state[fetchKey]; | ||
@@ -72,20 +72,18 @@ appContext.deleteState(fetchKey); | ||
if (initialFetch) { | ||
return new Promise(async (resolve) => { | ||
if (appContext.isServer && serverPrefetch) { | ||
if (isLazy) { | ||
onMounted(async () => { | ||
await load(); | ||
} | ||
if (appContext.isClient && !fetchState.serverPrefetched) { | ||
if (FLUE3_SSR_ENABLED) { | ||
onMounted(async () => { | ||
await load(); | ||
}); | ||
} | ||
else { | ||
}); | ||
} | ||
else { | ||
return new Promise(async (resolve) => { | ||
if ((appContext.isServer && !isLazy) | ||
|| (appContext.isClient && !fetchState.serverPrefetched)) { | ||
await load(); | ||
} | ||
} | ||
resolve(returns); | ||
}); | ||
resolve(returns); | ||
}); | ||
} | ||
} | ||
return returns; | ||
} |
import { useFetch } from './useFetch.js'; | ||
export const useLazyFetch = (key, hook, options) => { | ||
return useFetch(key, hook, { | ||
initialFetch: false, | ||
lazy: true, | ||
...(options ?? {}), | ||
}); | ||
}; |
import { AppContext } from '../types/AppContext.js'; | ||
export declare const defineMiddleware: (middleware: (appContext: AppContext) => Promise<void> | void) => (appContext: AppContext) => void | Promise<void>; | ||
import { AppMiddleware } from '../types/AppMiddleware.js'; | ||
export declare const defineMiddleware: (middleware: AppMiddleware) => (appContext: AppContext) => void | Promise<void>; |
{ | ||
"name": "flue3", | ||
"version": "0.0.6-dev.0", | ||
"version": "0.0.7-dev.0", | ||
"description": "flue3 SSR framework based on Vite", | ||
@@ -5,0 +5,0 @@ "author": "FL3NKEY", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89152
173
2228