vue-hooks-plus
Advanced tools
Comparing version 1.6.0-alpha.2 to 1.6.0-alpha.3
export type Resolve = (value: any) => void; | ||
export type interruptibleRejectType = (error: any) => void; | ||
export type InterruptibleRejectType = (error: any) => void; | ||
export type AsyncOrder = { | ||
task: ((resolve?: Resolve, reject?: interruptibleRejectType, index?: number) => void)[]; | ||
task: ((resolve?: Resolve, reject?: InterruptibleRejectType, index?: number) => void)[]; | ||
option?: { | ||
/** | ||
* Delay execution | ||
*/ | ||
delay?: number; | ||
/** | ||
* Preparation phase callback | ||
* @returns void | ||
*/ | ||
onReady?: () => void; | ||
onSuccess?: (result: any) => void; | ||
onError?: (err: any) => void; | ||
/** | ||
* Successful callback | ||
* @param result any | ||
* @returns void | ||
*/ | ||
onSuccess?: (result: unknown) => void; | ||
/** | ||
* Error callback | ||
* @param err unknown | ||
* @returns void | ||
*/ | ||
onError?: (err: unknown) => void; | ||
}; | ||
}; | ||
export default function useAsyncOrder({ task, option }: AsyncOrder): void; |
import type { Ref } from "vue"; | ||
export interface Actions { | ||
/** | ||
* Set state to `true` | ||
* @returns void | ||
*/ | ||
setTrue: () => void; | ||
/** | ||
* Set state to `false` | ||
* @returns void | ||
*/ | ||
setFalse: () => void; | ||
/** | ||
* Set state | ||
* @param value boolean | ||
* @returns void | ||
*/ | ||
set: (value: boolean) => void; | ||
/** | ||
* Toggle state | ||
* @returns void | ||
*/ | ||
toggle: () => void; | ||
} | ||
export default function useBoolean(defaultValue?: boolean): [Ref<boolean>, Actions]; | ||
export type UseBooleanResult = [Ref<boolean>, Actions]; | ||
export default function useBoolean(defaultValue?: boolean): UseBooleanResult; |
@@ -36,3 +36,2 @@ import { ref, watchEffect, onUnmounted } from "vue"; | ||
fetchInstance.state.params = cacheData.params; | ||
console.log("staleTime", staleTime); | ||
if (staleTime === -1 || new Date().getTime() - cacheData.time <= staleTime) { | ||
@@ -60,3 +59,2 @@ fetchInstance.state.loading = false; | ||
if (staleTime === -1 || new Date().getTime() - cacheData.time <= staleTime) { | ||
console.log("\u505C\u6B62\u8BF7\u6C42"); | ||
return { | ||
@@ -63,0 +61,0 @@ loading: false, |
@@ -27,20 +27,59 @@ import { Ref, WatchSource } from 'vue'; | ||
export interface BasicOptions<TData, TParams extends unknown[]> { | ||
/** | ||
* Init data. | ||
*/ | ||
initialData?: TData; | ||
/** | ||
* - The default is `false.` That is, the service is automatically executed during initialization. | ||
* - f set to `true`, you need to manually call `run` or r`unAsync` to trigger execution. | ||
*/ | ||
manual?: boolean; | ||
/** | ||
* The parameters passed to the service at the first default execution | ||
*/ | ||
defaultParams?: TParams; | ||
/** | ||
* Triggered before service execution | ||
* @param params TParams | ||
* @returns void | ||
*/ | ||
onBefore?: (params: TParams) => void; | ||
/** | ||
* Triggered when service resolve. | ||
* @param data TData | ||
* @param params TParams | ||
* @returns void | ||
*/ | ||
onSuccess?: (data: TData, params: TParams) => void; | ||
/** | ||
* Triggered when service reject. | ||
* @param e Error | ||
* @param params TParams | ||
* @returns void | ||
*/ | ||
onError?: (e: Error, params: TParams) => void; | ||
/** | ||
* Triggered when service execution is complete. | ||
* @param params TParams | ||
* @param data TData | ||
* @param e Error | ||
* @returns void | ||
*/ | ||
onFinally?: (params: TParams, data?: TData, e?: Error) => void; | ||
defaultParams?: TParams; | ||
/** | ||
* refreshDeps | ||
* Is the current request ready | ||
*/ | ||
ready?: Ref<boolean> | boolean; | ||
/** | ||
* Dependent on responsive objects, and the `watch` incoming listener object usage for `vue`. | ||
*/ | ||
refreshDeps?: WatchSource[] | boolean; | ||
refreshDepsAction?: () => void; | ||
/** | ||
* loadingDelay | ||
* Set the delay time for `loading` to become `true`. | ||
* | ||
*/ | ||
loadingDelay?: number | Ref<number>; | ||
/** | ||
* formatResult | ||
* Format the request results, which recommend to use `useFormatResult` | ||
* @param data TData | ||
@@ -51,41 +90,86 @@ * @returns unknown need cover TData | ||
/** | ||
* polling | ||
* Polling interval, in milliseconds. If the value is greater than 0, the polling mode is activated. | ||
*/ | ||
pollingInterval?: Ref<number> | number; | ||
/** | ||
* Whether to continue polling when the page is hidden. If set to false, polling will be temporarily paused when the page is hidden, and resume when the page is visible again. | ||
*/ | ||
pollingWhenHidden?: boolean; | ||
/** | ||
* refreshOnWindowFocus | ||
* Number of polling error retries. If set to -1, `an infinite number of times`. | ||
*/ | ||
pollingErrorRetryCount?: number; | ||
/** | ||
* Whether to re-initiate the request when the screen refocus or revisible. | ||
*/ | ||
refreshOnWindowFocus?: Ref<boolean> | boolean; | ||
/** | ||
* Re-request interval, in milliseconds. | ||
*/ | ||
focusTimespan?: Ref<number> | number; | ||
/** | ||
* debounce | ||
* Debounce delay time, in milliseconds. After setting, enter the debounce mode. | ||
*/ | ||
debounceWait?: Ref<number> | number; | ||
/** | ||
* Execute the request before the delay starts. | ||
*/ | ||
debounceLeading?: Ref<boolean> | boolean; | ||
/** | ||
* Execute the request after the delay ends. | ||
*/ | ||
debounceTrailing?: Ref<boolean> | boolean; | ||
/** | ||
* The maximum time request is allowed to be delayed before it’s executed. | ||
*/ | ||
debounceMaxWait?: Ref<number> | number; | ||
/** | ||
* throttle | ||
* Throttle wait time, in milliseconds. After setting, enter the throttle mode. | ||
*/ | ||
throttleWait?: Ref<number> | number; | ||
/** | ||
* Execute the request before throttling starts. | ||
*/ | ||
throttleLeading?: Ref<boolean> | boolean; | ||
/** | ||
* Execute the request after throttling ends. | ||
*/ | ||
throttleTrailing?: Ref<boolean> | boolean; | ||
/** | ||
* cache | ||
* A unique ID of the request. If `cacheKey` is set, we will enable the caching mechanism. The data of the same `cacheKey` is globally synchronized. | ||
*/ | ||
cacheKey?: string; | ||
/** | ||
* - Set the cache time. By default, the cached data will be cleared after 5 minutes. | ||
* - If set to `-1`, the cached data will never expire. | ||
*/ | ||
cacheTime?: number; | ||
/** | ||
* - Time to consider the cached data is fresh. Within this time interval, the request will not be re-initiated. | ||
* - If set to `-1`, it means that the data is always fresh | ||
*/ | ||
staleTime?: number; | ||
/** | ||
* - Custom set cache. | ||
* - `setCache` and `getCache` need to be used together. | ||
* - In the custom cache mode, `cacheTime` and `clearCache` are useless, please implement it yourself according to the actual situation. | ||
* @param data CachedData | ||
* @returns void | ||
*/ | ||
setCache?: (data: CachedData<TData, TParams>) => void; | ||
/** | ||
* Custom get cache | ||
* @param params TParams | ||
* @returns CachedData | ||
*/ | ||
getCache?: (params: TParams) => CachedData<TData, TParams> | undefined; | ||
/** | ||
* retry | ||
* The number of retries. If set to `-1`, it will try again indefinitely. | ||
*/ | ||
retryCount?: number; | ||
retryInterval?: number; | ||
/** | ||
* ready | ||
* - Retry interval in milliseconds. | ||
* If not set, the simple exponential backoff algorithm will be used by default, taking `1000 * 2 ** retryCount`, that is, waiting for 2s for the first retry, and 4s for the second retry. By analogy, if it is greater than 30s, take 30s. | ||
*/ | ||
ready?: Ref<boolean> | boolean; | ||
retryInterval?: number; | ||
} | ||
@@ -102,11 +186,41 @@ export type Options<TData, TParams extends unknown[], TPlugin> = { | ||
export interface Result<TData, TParams extends unknown[]> { | ||
/** | ||
* Is the service being executed. | ||
*/ | ||
loading: Ref<boolean>; | ||
/** | ||
* Data returned by service. | ||
*/ | ||
data: Ref<TData | undefined>; | ||
/** | ||
* Exception thrown by service. | ||
*/ | ||
error: Ref<Error | undefined>; | ||
/** | ||
* params An array of parameters for the service being executed. For example, you triggered `run(1, 2, 3)`, then params is equal to `[1, 2, 3]`. | ||
*/ | ||
params: Ref<TParams | []>; | ||
/** | ||
* Ignore the current promise response. | ||
*/ | ||
cancel: Fetch<TData, TParams>['cancel']; | ||
/** | ||
* Use the last params, call `run` again. | ||
*/ | ||
refresh: Fetch<TData, TParams>['refresh']; | ||
/** | ||
* Use the last params, call `runAsync` again. | ||
*/ | ||
refreshAsync: Fetch<TData, TParams>['refreshAsync']; | ||
/** | ||
* Manually trigger the execution of the service, and the parameters will be passed to the service. | ||
*/ | ||
run: Fetch<TData, TParams>['run']; | ||
/** | ||
* Automatic handling of exceptions, feedback through `onError` | ||
*/ | ||
runAsync: Fetch<TData, TParams>['runAsync']; | ||
/** | ||
* Mutate `data` directly | ||
*/ | ||
mutate: Fetch<TData, TParams>['mutate']; | ||
@@ -113,0 +227,0 @@ } |
export type Resolve = (value: any) => void; | ||
export type interruptibleRejectType = (error: any) => void; | ||
export type InterruptibleRejectType = (error: any) => void; | ||
export type AsyncOrder = { | ||
task: ((resolve?: Resolve, reject?: interruptibleRejectType, index?: number) => void)[]; | ||
task: ((resolve?: Resolve, reject?: InterruptibleRejectType, index?: number) => void)[]; | ||
option?: { | ||
/** | ||
* Delay execution | ||
*/ | ||
delay?: number; | ||
/** | ||
* Preparation phase callback | ||
* @returns void | ||
*/ | ||
onReady?: () => void; | ||
onSuccess?: (result: any) => void; | ||
onError?: (err: any) => void; | ||
/** | ||
* Successful callback | ||
* @param result any | ||
* @returns void | ||
*/ | ||
onSuccess?: (result: unknown) => void; | ||
/** | ||
* Error callback | ||
* @param err unknown | ||
* @returns void | ||
*/ | ||
onError?: (err: unknown) => void; | ||
}; | ||
}; | ||
export default function useAsyncOrder({ task, option }: AsyncOrder): void; |
import type { Ref } from "vue"; | ||
export interface Actions { | ||
/** | ||
* Set state to `true` | ||
* @returns void | ||
*/ | ||
setTrue: () => void; | ||
/** | ||
* Set state to `false` | ||
* @returns void | ||
*/ | ||
setFalse: () => void; | ||
/** | ||
* Set state | ||
* @param value boolean | ||
* @returns void | ||
*/ | ||
set: (value: boolean) => void; | ||
/** | ||
* Toggle state | ||
* @returns void | ||
*/ | ||
toggle: () => void; | ||
} | ||
export default function useBoolean(defaultValue?: boolean): [Ref<boolean>, Actions]; | ||
export type UseBooleanResult = [Ref<boolean>, Actions]; | ||
export default function useBoolean(defaultValue?: boolean): UseBooleanResult; |
@@ -58,3 +58,2 @@ "use strict"; | ||
fetchInstance.state.params = cacheData.params; | ||
console.log("staleTime", staleTime); | ||
if (staleTime === -1 || new Date().getTime() - cacheData.time <= staleTime) { | ||
@@ -82,3 +81,2 @@ fetchInstance.state.loading = false; | ||
if (staleTime === -1 || new Date().getTime() - cacheData.time <= staleTime) { | ||
console.log("\u505C\u6B62\u8BF7\u6C42"); | ||
return { | ||
@@ -85,0 +83,0 @@ loading: false, |
@@ -27,20 +27,59 @@ import { Ref, WatchSource } from 'vue'; | ||
export interface BasicOptions<TData, TParams extends unknown[]> { | ||
/** | ||
* Init data. | ||
*/ | ||
initialData?: TData; | ||
/** | ||
* - The default is `false.` That is, the service is automatically executed during initialization. | ||
* - f set to `true`, you need to manually call `run` or r`unAsync` to trigger execution. | ||
*/ | ||
manual?: boolean; | ||
/** | ||
* The parameters passed to the service at the first default execution | ||
*/ | ||
defaultParams?: TParams; | ||
/** | ||
* Triggered before service execution | ||
* @param params TParams | ||
* @returns void | ||
*/ | ||
onBefore?: (params: TParams) => void; | ||
/** | ||
* Triggered when service resolve. | ||
* @param data TData | ||
* @param params TParams | ||
* @returns void | ||
*/ | ||
onSuccess?: (data: TData, params: TParams) => void; | ||
/** | ||
* Triggered when service reject. | ||
* @param e Error | ||
* @param params TParams | ||
* @returns void | ||
*/ | ||
onError?: (e: Error, params: TParams) => void; | ||
/** | ||
* Triggered when service execution is complete. | ||
* @param params TParams | ||
* @param data TData | ||
* @param e Error | ||
* @returns void | ||
*/ | ||
onFinally?: (params: TParams, data?: TData, e?: Error) => void; | ||
defaultParams?: TParams; | ||
/** | ||
* refreshDeps | ||
* Is the current request ready | ||
*/ | ||
ready?: Ref<boolean> | boolean; | ||
/** | ||
* Dependent on responsive objects, and the `watch` incoming listener object usage for `vue`. | ||
*/ | ||
refreshDeps?: WatchSource[] | boolean; | ||
refreshDepsAction?: () => void; | ||
/** | ||
* loadingDelay | ||
* Set the delay time for `loading` to become `true`. | ||
* | ||
*/ | ||
loadingDelay?: number | Ref<number>; | ||
/** | ||
* formatResult | ||
* Format the request results, which recommend to use `useFormatResult` | ||
* @param data TData | ||
@@ -51,41 +90,86 @@ * @returns unknown need cover TData | ||
/** | ||
* polling | ||
* Polling interval, in milliseconds. If the value is greater than 0, the polling mode is activated. | ||
*/ | ||
pollingInterval?: Ref<number> | number; | ||
/** | ||
* Whether to continue polling when the page is hidden. If set to false, polling will be temporarily paused when the page is hidden, and resume when the page is visible again. | ||
*/ | ||
pollingWhenHidden?: boolean; | ||
/** | ||
* refreshOnWindowFocus | ||
* Number of polling error retries. If set to -1, `an infinite number of times`. | ||
*/ | ||
pollingErrorRetryCount?: number; | ||
/** | ||
* Whether to re-initiate the request when the screen refocus or revisible. | ||
*/ | ||
refreshOnWindowFocus?: Ref<boolean> | boolean; | ||
/** | ||
* Re-request interval, in milliseconds. | ||
*/ | ||
focusTimespan?: Ref<number> | number; | ||
/** | ||
* debounce | ||
* Debounce delay time, in milliseconds. After setting, enter the debounce mode. | ||
*/ | ||
debounceWait?: Ref<number> | number; | ||
/** | ||
* Execute the request before the delay starts. | ||
*/ | ||
debounceLeading?: Ref<boolean> | boolean; | ||
/** | ||
* Execute the request after the delay ends. | ||
*/ | ||
debounceTrailing?: Ref<boolean> | boolean; | ||
/** | ||
* The maximum time request is allowed to be delayed before it’s executed. | ||
*/ | ||
debounceMaxWait?: Ref<number> | number; | ||
/** | ||
* throttle | ||
* Throttle wait time, in milliseconds. After setting, enter the throttle mode. | ||
*/ | ||
throttleWait?: Ref<number> | number; | ||
/** | ||
* Execute the request before throttling starts. | ||
*/ | ||
throttleLeading?: Ref<boolean> | boolean; | ||
/** | ||
* Execute the request after throttling ends. | ||
*/ | ||
throttleTrailing?: Ref<boolean> | boolean; | ||
/** | ||
* cache | ||
* A unique ID of the request. If `cacheKey` is set, we will enable the caching mechanism. The data of the same `cacheKey` is globally synchronized. | ||
*/ | ||
cacheKey?: string; | ||
/** | ||
* - Set the cache time. By default, the cached data will be cleared after 5 minutes. | ||
* - If set to `-1`, the cached data will never expire. | ||
*/ | ||
cacheTime?: number; | ||
/** | ||
* - Time to consider the cached data is fresh. Within this time interval, the request will not be re-initiated. | ||
* - If set to `-1`, it means that the data is always fresh | ||
*/ | ||
staleTime?: number; | ||
/** | ||
* - Custom set cache. | ||
* - `setCache` and `getCache` need to be used together. | ||
* - In the custom cache mode, `cacheTime` and `clearCache` are useless, please implement it yourself according to the actual situation. | ||
* @param data CachedData | ||
* @returns void | ||
*/ | ||
setCache?: (data: CachedData<TData, TParams>) => void; | ||
/** | ||
* Custom get cache | ||
* @param params TParams | ||
* @returns CachedData | ||
*/ | ||
getCache?: (params: TParams) => CachedData<TData, TParams> | undefined; | ||
/** | ||
* retry | ||
* The number of retries. If set to `-1`, it will try again indefinitely. | ||
*/ | ||
retryCount?: number; | ||
retryInterval?: number; | ||
/** | ||
* ready | ||
* - Retry interval in milliseconds. | ||
* If not set, the simple exponential backoff algorithm will be used by default, taking `1000 * 2 ** retryCount`, that is, waiting for 2s for the first retry, and 4s for the second retry. By analogy, if it is greater than 30s, take 30s. | ||
*/ | ||
ready?: Ref<boolean> | boolean; | ||
retryInterval?: number; | ||
} | ||
@@ -102,11 +186,41 @@ export type Options<TData, TParams extends unknown[], TPlugin> = { | ||
export interface Result<TData, TParams extends unknown[]> { | ||
/** | ||
* Is the service being executed. | ||
*/ | ||
loading: Ref<boolean>; | ||
/** | ||
* Data returned by service. | ||
*/ | ||
data: Ref<TData | undefined>; | ||
/** | ||
* Exception thrown by service. | ||
*/ | ||
error: Ref<Error | undefined>; | ||
/** | ||
* params An array of parameters for the service being executed. For example, you triggered `run(1, 2, 3)`, then params is equal to `[1, 2, 3]`. | ||
*/ | ||
params: Ref<TParams | []>; | ||
/** | ||
* Ignore the current promise response. | ||
*/ | ||
cancel: Fetch<TData, TParams>['cancel']; | ||
/** | ||
* Use the last params, call `run` again. | ||
*/ | ||
refresh: Fetch<TData, TParams>['refresh']; | ||
/** | ||
* Use the last params, call `runAsync` again. | ||
*/ | ||
refreshAsync: Fetch<TData, TParams>['refreshAsync']; | ||
/** | ||
* Manually trigger the execution of the service, and the parameters will be passed to the service. | ||
*/ | ||
run: Fetch<TData, TParams>['run']; | ||
/** | ||
* Automatic handling of exceptions, feedback through `onError` | ||
*/ | ||
runAsync: Fetch<TData, TParams>['runAsync']; | ||
/** | ||
* Mutate `data` directly | ||
*/ | ||
mutate: Fetch<TData, TParams>['mutate']; | ||
@@ -113,0 +227,0 @@ } |
{ | ||
"name": "vue-hooks-plus", | ||
"version": "1.6.0-alpha.2", | ||
"version": "1.6.0-alpha.3", | ||
"description": "Vue hooks library", | ||
@@ -5,0 +5,0 @@ "files": [ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
1011112
19950