From 4d7577ee399a1fd1cfa9b2c40ad55028f217638a Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Thu, 13 Apr 2023 09:56:47 +0200 Subject: [PATCH] feat(types)!: rename `MaybeComputedRef` to `MaybeRefOrGetter` --- packages/core/onKeyStroke/index.ts | 6 ++-- packages/core/unrefElement/index.ts | 4 +-- packages/core/useBase64/index.ts | 20 ++++++------- packages/core/useClipboard/index.ts | 6 ++-- packages/core/useCloned/index.ts | 4 +-- packages/core/useCssVar/index.ts | 4 +-- packages/core/useCycleList/index.ts | 4 +-- packages/core/useDebouncedRefHistory/index.ts | 4 +-- packages/core/useDraggable/index.ts | 16 +++++------ packages/core/useDropZone/index.ts | 4 +-- packages/core/useElementByPoint/index.ts | 6 ++-- packages/core/useElementHover/index.ts | 4 +-- packages/core/useElementVisibility/index.ts | 4 +-- packages/core/useEventListener/index.ts | 18 ++++++------ packages/core/useFavicon/index.ts | 6 ++-- packages/core/useFetch/index.ts | 28 +++++++++---------- packages/core/useFileSystemAccess/index.ts | 4 +-- packages/core/useImage/index.ts | 4 +-- packages/core/useInfiniteScroll/index.ts | 4 +-- packages/core/useLocalStorage/index.ts | 14 +++++----- packages/core/useMagicKeys/index.ts | 4 +-- packages/core/useMediaControls/index.ts | 8 +++--- packages/core/useMediaQuery/index.ts | 4 +-- packages/core/useParentElement/index.ts | 4 +-- packages/core/usePointerSwipe/index.ts | 4 +-- packages/core/usePrevious/index.ts | 8 +++--- packages/core/useScriptTag/index.ts | 4 +-- packages/core/useScroll/index.ts | 6 ++-- packages/core/useScrollLock/index.ts | 4 +-- packages/core/useSessionStorage/index.ts | 14 +++++----- packages/core/useShare/index.ts | 6 ++-- packages/core/useSpeechRecognition/index.ts | 4 +-- packages/core/useSpeechSynthesis/index.ts | 6 ++-- packages/core/useStorage/index.ts | 14 +++++----- packages/core/useStorageAsync/index.ts | 14 +++++----- packages/core/useSwipe/index.ts | 4 +-- packages/core/useTimeAgo/index.ts | 8 +++--- packages/core/useTimeoutPoll/index.ts | 4 +-- packages/core/useTitle/index.ts | 6 ++-- packages/core/useTransition/index.ts | 10 +++---- packages/core/useVibrate/index.ts | 4 +-- packages/core/useWebSocket/index.ts | 4 +-- .../integrations/useAsyncValidator/index.ts | 6 ++-- packages/integrations/useChangeCase/index.ts | 6 ++-- packages/integrations/useFuse/index.ts | 8 +++--- packages/integrations/useIDBKeyval/index.ts | 4 +-- packages/integrations/useJwt/index.ts | 4 +-- packages/integrations/useNProgress/index.ts | 4 +-- packages/integrations/useQRCode/index.ts | 4 +-- packages/integrations/useSortable/index.ts | 12 ++++---- .../math/createGenericProjection/index.ts | 10 +++---- packages/math/createProjection/index.ts | 6 ++-- packages/math/logicAnd/index.ts | 4 +-- packages/math/logicNot/index.ts | 4 +-- packages/math/logicOr/index.ts | 4 +-- packages/math/useAbs/index.ts | 4 +-- packages/math/useAverage/index.ts | 6 ++-- packages/math/useCeil/index.ts | 4 +-- packages/math/useClamp/index.ts | 16 +++++------ packages/math/useFloor/index.ts | 4 +-- packages/math/useMax/index.ts | 6 ++-- packages/math/useMin/index.ts | 6 ++-- packages/math/usePrecision/index.ts | 8 +++--- packages/math/useProjection/index.ts | 8 +++--- packages/math/useRound/index.ts | 4 +-- packages/math/useSum/index.ts | 6 ++-- packages/math/useTrunc/index.ts | 4 +-- packages/math/utils.ts | 4 +-- packages/shared/reactify/index.ts | 4 +-- packages/shared/refAutoReset/index.ts | 4 +-- packages/shared/refDebounced/index.ts | 4 +-- packages/shared/toRef/index.ts | 11 ++++---- packages/shared/toValue/index.ts | 4 +-- packages/shared/until/index.ts | 12 ++++---- packages/shared/useArrayDifference/index.ts | 10 +++---- packages/shared/useArrayEvery/index.ts | 6 ++-- packages/shared/useArrayFilter/index.ts | 4 +-- packages/shared/useArrayFind/index.ts | 6 ++-- packages/shared/useArrayFindIndex/index.ts | 6 ++-- packages/shared/useArrayFindLast/index.ts | 6 ++-- packages/shared/useArrayIncludes/index.ts | 20 ++++++------- packages/shared/useArrayJoin/index.ts | 6 ++-- packages/shared/useArrayMap/index.ts | 4 +-- packages/shared/useArrayReduce/index.ts | 10 +++---- packages/shared/useArraySome/index.ts | 6 ++-- packages/shared/useArrayUnique/index.ts | 4 +-- packages/shared/useDateFormat/index.ts | 4 +-- packages/shared/useDebounceFn/index.ts | 4 +-- packages/shared/useInterval/index.ts | 8 +++--- packages/shared/useIntervalFn/index.ts | 4 +-- packages/shared/useThrottleFn/index.ts | 4 +-- packages/shared/useTimeoutFn/index.ts | 4 +-- packages/shared/useToNumber/index.ts | 4 +-- packages/shared/useToString/index.ts | 4 +-- packages/shared/useToggle/index.ts | 6 ++-- packages/shared/utils/filters.ts | 8 +++--- packages/shared/utils/types.ts | 15 ++-------- packages/shared/watchAtMost/index.ts | 4 +-- packages/shared/watchDebounced/index.ts | 4 +-- packages/shared/watchThrottled/index.ts | 4 +-- 100 files changed, 329 insertions(+), 339 deletions(-) diff --git a/packages/core/onKeyStroke/index.ts b/packages/core/onKeyStroke/index.ts index 9f0a01c5d0e..d15bc02398f 100644 --- a/packages/core/onKeyStroke/index.ts +++ b/packages/core/onKeyStroke/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' import { useEventListener } from '../useEventListener' import { defaultWindow } from '../_configurable' @@ -8,14 +8,14 @@ export type KeyFilter = true | string | string[] | KeyPredicate export type KeyStrokeEventName = 'keydown' | 'keypress' | 'keyup' export interface OnKeyStrokeOptions { eventName?: KeyStrokeEventName - target?: MaybeComputedRef + target?: MaybeRefOrGetter passive?: boolean /** * Set to `true` to ignore repeated events when the key is being held down. * * @default false */ - dedupe?: MaybeComputedRef + dedupe?: MaybeRefOrGetter } function createKeyPredicate(keyFilter: KeyFilter): KeyPredicate { diff --git a/packages/core/unrefElement/index.ts b/packages/core/unrefElement/index.ts index 076166733a8..aaa73c85775 100644 --- a/packages/core/unrefElement/index.ts +++ b/packages/core/unrefElement/index.ts @@ -1,10 +1,10 @@ import type { ComponentPublicInstance } from 'vue-demi' -import type { MaybeComputedRef, MaybeRef } from '@vueuse/shared' +import type { MaybeRef, MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' export type VueInstance = ComponentPublicInstance export type MaybeElementRef = MaybeRef -export type MaybeComputedElementRef = MaybeComputedRef +export type MaybeComputedElementRef = MaybeRefOrGetter export type MaybeElement = HTMLElement | SVGElement | VueInstance | undefined | null export type UnRefElementReturn = T extends VueInstance ? Exclude : T | undefined diff --git a/packages/core/useBase64/index.ts b/packages/core/useBase64/index.ts index b51833e8643..f558e4380c6 100644 --- a/packages/core/useBase64/index.ts +++ b/packages/core/useBase64/index.ts @@ -1,6 +1,6 @@ import type { Ref } from 'vue-demi' import { isRef, ref, watch } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { isClient, isFunction, toValue } from '@vueuse/shared' import { getDefaultSerialization } from './serialization' @@ -25,15 +25,15 @@ export interface UseBase64Return { execute: () => Promise } -export function useBase64(target: MaybeComputedRef): UseBase64Return -export function useBase64(target: MaybeComputedRef): UseBase64Return -export function useBase64(target: MaybeComputedRef): UseBase64Return -export function useBase64(target: MaybeComputedRef, options?: ToDataURLOptions): UseBase64Return -export function useBase64(target: MaybeComputedRef, options?: ToDataURLOptions): UseBase64Return -export function useBase64>(target: MaybeComputedRef, options?: UseBase64ObjectOptions): UseBase64Return -export function useBase64>(target: MaybeComputedRef, options?: UseBase64ObjectOptions): UseBase64Return -export function useBase64>(target: MaybeComputedRef, options?: UseBase64ObjectOptions): UseBase64Return -export function useBase64(target: MaybeComputedRef, options?: UseBase64ObjectOptions): UseBase64Return +export function useBase64(target: MaybeRefOrGetter): UseBase64Return +export function useBase64(target: MaybeRefOrGetter): UseBase64Return +export function useBase64(target: MaybeRefOrGetter): UseBase64Return +export function useBase64(target: MaybeRefOrGetter, options?: ToDataURLOptions): UseBase64Return +export function useBase64(target: MaybeRefOrGetter, options?: ToDataURLOptions): UseBase64Return +export function useBase64>(target: MaybeRefOrGetter, options?: UseBase64ObjectOptions): UseBase64Return +export function useBase64>(target: MaybeRefOrGetter, options?: UseBase64ObjectOptions): UseBase64Return +export function useBase64>(target: MaybeRefOrGetter, options?: UseBase64ObjectOptions): UseBase64Return +export function useBase64(target: MaybeRefOrGetter, options?: UseBase64ObjectOptions): UseBase64Return export function useBase64( target: any, options?: any, diff --git a/packages/core/useClipboard/index.ts b/packages/core/useClipboard/index.ts index b29c0c8f2ac..894da5e036d 100644 --- a/packages/core/useClipboard/index.ts +++ b/packages/core/useClipboard/index.ts @@ -1,6 +1,6 @@ /* this implementation is original ported from https://github.com/logaretm/vue-use-web by Abdelrahman Awad */ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue, useTimeoutFn } from '@vueuse/shared' import type { ComputedRef, Ref } from 'vue-demi' import { computed, ref } from 'vue-demi' @@ -52,8 +52,8 @@ export interface UseClipboardReturn { * @param options */ export function useClipboard(options?: UseClipboardOptions): UseClipboardReturn -export function useClipboard(options: UseClipboardOptions>): UseClipboardReturn -export function useClipboard(options: UseClipboardOptions | undefined> = {}): UseClipboardReturn { +export function useClipboard(options: UseClipboardOptions>): UseClipboardReturn +export function useClipboard(options: UseClipboardOptions | undefined> = {}): UseClipboardReturn { const { navigator = defaultNavigator, read = false, diff --git a/packages/core/useCloned/index.ts b/packages/core/useCloned/index.ts index d40080181f0..004ba1545cd 100644 --- a/packages/core/useCloned/index.ts +++ b/packages/core/useCloned/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import type { ComputedRef, WatchOptions } from 'vue-demi' import { isRef, ref, unref, watch } from 'vue-demi' @@ -36,7 +36,7 @@ export function cloneFnJSON(source: T): T { } export function useCloned( - source: MaybeComputedRef, + source: MaybeRefOrGetter, options: UseClonedOptions = {}, ) { const cloned = ref({} as T) diff --git a/packages/core/useCssVar/index.ts b/packages/core/useCssVar/index.ts index 1392b4a9df3..c3c387e66f3 100644 --- a/packages/core/useCssVar/index.ts +++ b/packages/core/useCssVar/index.ts @@ -1,6 +1,6 @@ import { useMutationObserver } from '@vueuse/core' import { computed, ref, watch } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' import type { ConfigurableWindow } from '../_configurable' import { defaultWindow } from '../_configurable' @@ -25,7 +25,7 @@ export interface UseCssVarOptions extends ConfigurableWindow { * @param options */ export function useCssVar( - prop: MaybeComputedRef, + prop: MaybeRefOrGetter, target?: MaybeElementRef, options: UseCssVarOptions = {}, ) { diff --git a/packages/core/useCycleList/index.ts b/packages/core/useCycleList/index.ts index 0c0cdb9a957..9f44468c8e3 100644 --- a/packages/core/useCycleList/index.ts +++ b/packages/core/useCycleList/index.ts @@ -1,7 +1,7 @@ import type { Ref } from 'vue-demi' import { computed, shallowRef, watch } from 'vue-demi' import { toRef, toValue } from '@vueuse/shared' -import type { MaybeComputedRef, MaybeRef } from '@vueuse/shared' +import type { MaybeRef, MaybeRefOrGetter } from '@vueuse/shared' export interface UseCycleListOptions { /** @@ -26,7 +26,7 @@ export interface UseCycleListOptions { * * @see https://vueuse.org/useCycleList */ -export function useCycleList(list: MaybeComputedRef, options?: UseCycleListOptions): UseCycleListReturn { +export function useCycleList(list: MaybeRefOrGetter, options?: UseCycleListOptions): UseCycleListReturn { const state = shallowRef(getInitialValue()) as Ref const listRef = toRef(list) diff --git a/packages/core/useDebouncedRefHistory/index.ts b/packages/core/useDebouncedRefHistory/index.ts index 54db46209ea..288b6aad0eb 100644 --- a/packages/core/useDebouncedRefHistory/index.ts +++ b/packages/core/useDebouncedRefHistory/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { debounceFilter } from '@vueuse/shared' import type { Ref } from 'vue-demi' import type { UseRefHistoryOptions, UseRefHistoryReturn } from '../useRefHistory' @@ -13,7 +13,7 @@ import { useRefHistory } from '../useRefHistory' */ export function useDebouncedRefHistory( source: Ref, - options: Omit, 'eventFilter'> & { debounce?: MaybeComputedRef } = {}, + options: Omit, 'eventFilter'> & { debounce?: MaybeRefOrGetter } = {}, ): UseRefHistoryReturn { const filter = options.debounce ? debounceFilter(options.debounce) : undefined const history = useRefHistory(source, { ...options, eventFilter: filter }) diff --git a/packages/core/useDraggable/index.ts b/packages/core/useDraggable/index.ts index 37862fd8940..387547781e1 100644 --- a/packages/core/useDraggable/index.ts +++ b/packages/core/useDraggable/index.ts @@ -1,5 +1,5 @@ import { computed, ref } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { isClient, toRefs, toValue } from '@vueuse/shared' import { useEventListener } from '../useEventListener' import type { PointerType, Position } from '../types' @@ -11,35 +11,35 @@ export interface UseDraggableOptions { * * @default false */ - exact?: MaybeComputedRef + exact?: MaybeRefOrGetter /** * Prevent events defaults * * @default false */ - preventDefault?: MaybeComputedRef + preventDefault?: MaybeRefOrGetter /** * Prevent events propagation * * @default false */ - stopPropagation?: MaybeComputedRef + stopPropagation?: MaybeRefOrGetter /** * Element to attach `pointermove` and `pointerup` events to. * * @default window */ - draggingElement?: MaybeComputedRef + draggingElement?: MaybeRefOrGetter /** * Handle that triggers the drag event * * @default target */ - handle?: MaybeComputedRef + handle?: MaybeRefOrGetter /** * Pointer types that listen to. @@ -53,7 +53,7 @@ export interface UseDraggableOptions { * * @default { x: 0, y: 0 } */ - initialValue?: MaybeComputedRef + initialValue?: MaybeRefOrGetter /** * Callback when the dragging starts. Return `false` to prevent dragging. @@ -86,7 +86,7 @@ export interface UseDraggableOptions { * @param options */ export function useDraggable( - target: MaybeComputedRef, + target: MaybeRefOrGetter, options: UseDraggableOptions = {}, ) { const { diff --git a/packages/core/useDropZone/index.ts b/packages/core/useDropZone/index.ts index 28ff27000e2..5a499978aca 100644 --- a/packages/core/useDropZone/index.ts +++ b/packages/core/useDropZone/index.ts @@ -1,6 +1,6 @@ import { ref } from 'vue-demi' import type { Ref } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { isClient } from '@vueuse/shared' import { useEventListener } from '../useEventListener' @@ -9,7 +9,7 @@ export interface UseDropZoneReturn { } export function useDropZone( - target: MaybeComputedRef, + target: MaybeRefOrGetter, onDrop?: (files: File[] | null) => void, ): UseDropZoneReturn { const isOverDropZone = ref(false) diff --git a/packages/core/useElementByPoint/index.ts b/packages/core/useElementByPoint/index.ts index 2cc9bd4a64e..f865f52d81d 100644 --- a/packages/core/useElementByPoint/index.ts +++ b/packages/core/useElementByPoint/index.ts @@ -1,13 +1,13 @@ import { ref } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' import { useRafFn } from '../useRafFn' import type { ConfigurableDocument } from '../_configurable' import { defaultDocument } from '../_configurable' export interface UseElementByPointOptions extends ConfigurableDocument { - x: MaybeComputedRef - y: MaybeComputedRef + x: MaybeRefOrGetter + y: MaybeRefOrGetter } /** diff --git a/packages/core/useElementHover/index.ts b/packages/core/useElementHover/index.ts index bf091e7b0c7..8883a4d4c61 100644 --- a/packages/core/useElementHover/index.ts +++ b/packages/core/useElementHover/index.ts @@ -1,6 +1,6 @@ import type { Ref } from 'vue-demi' import { ref } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { useEventListener } from '../useEventListener' import type { ConfigurableWindow } from '../_configurable' import { defaultWindow } from '../_configurable' @@ -10,7 +10,7 @@ export interface UseElementHoverOptions extends ConfigurableWindow { delayLeave?: number } -export function useElementHover(el: MaybeComputedRef, options: UseElementHoverOptions = {}): Ref { +export function useElementHover(el: MaybeRefOrGetter, options: UseElementHoverOptions = {}): Ref { const { delayEnter = 0, delayLeave = 0, diff --git a/packages/core/useElementVisibility/index.ts b/packages/core/useElementVisibility/index.ts index 59f0c1d6ebc..7bc999a145b 100644 --- a/packages/core/useElementVisibility/index.ts +++ b/packages/core/useElementVisibility/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { ref } from 'vue-demi' import type { MaybeComputedElementRef } from '../unrefElement' import { useIntersectionObserver } from '../useIntersectionObserver' @@ -6,7 +6,7 @@ import type { ConfigurableWindow } from '../_configurable' import { defaultWindow } from '../_configurable' export interface UseElementVisibilityOptions extends ConfigurableWindow { - scrollTarget?: MaybeComputedRef + scrollTarget?: MaybeRefOrGetter } /** diff --git a/packages/core/useEventListener/index.ts b/packages/core/useEventListener/index.ts index 4fa5421c12a..89630f22e35 100644 --- a/packages/core/useEventListener/index.ts +++ b/packages/core/useEventListener/index.ts @@ -1,4 +1,4 @@ -import type { Arrayable, Fn, MaybeComputedRef } from '@vueuse/shared' +import type { Arrayable, Fn, MaybeRefOrGetter } from '@vueuse/shared' import { isString, noop, toValue, tryOnScopeDispose } from '@vueuse/shared' import { watch } from 'vue-demi' import type { MaybeElementRef } from '../unrefElement' @@ -30,7 +30,7 @@ export interface GeneralEventListener { export function useEventListener( event: Arrayable, listener: Arrayable<(this: Window, ev: WindowEventMap[E]) => any>, - options?: MaybeComputedRef + options?: MaybeRefOrGetter ): Fn /** @@ -48,7 +48,7 @@ export function useEventListener( target: Window, event: Arrayable, listener: Arrayable<(this: Window, ev: WindowEventMap[E]) => any>, - options?: MaybeComputedRef + options?: MaybeRefOrGetter ): Fn /** @@ -66,7 +66,7 @@ export function useEventListener( target: DocumentOrShadowRoot, event: Arrayable, listener: Arrayable<(this: Document, ev: DocumentEventMap[E]) => any>, - options?: MaybeComputedRef + options?: MaybeRefOrGetter ): Fn /** @@ -84,7 +84,7 @@ export function useEventListener( target: InferEventTarget, event: Arrayable, listener: Arrayable>, - options?: MaybeComputedRef + options?: MaybeRefOrGetter ): Fn /** @@ -99,17 +99,17 @@ export function useEventListener( * @param options */ export function useEventListener( - target: MaybeComputedRef, + target: MaybeRefOrGetter, event: Arrayable, listener: Arrayable>, - options?: MaybeComputedRef + options?: MaybeRefOrGetter ): Fn export function useEventListener(...args: any[]) { - let target: MaybeComputedRef | undefined + let target: MaybeRefOrGetter | undefined let events: Arrayable let listeners: Arrayable - let options: MaybeComputedRef | undefined + let options: MaybeRefOrGetter | undefined if (isString(args[0]) || Array.isArray(args[0])) { [events, listeners, options] = args diff --git a/packages/core/useFavicon/index.ts b/packages/core/useFavicon/index.ts index ea1454ff152..b3176742c6a 100644 --- a/packages/core/useFavicon/index.ts +++ b/packages/core/useFavicon/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef, MaybeReadonlyRef, MaybeRef } from '@vueuse/shared' +import type { MaybeRef, MaybeRefOrGetter } from '@vueuse/shared' import { isString, toRef } from '@vueuse/shared' import type { ComputedRef, Ref } from 'vue-demi' import { watch } from 'vue-demi' @@ -18,7 +18,7 @@ export interface UseFaviconOptions extends ConfigurableDocument { * @param options */ export function useFavicon( - newIcon: MaybeReadonlyRef, + newIcon: MaybeRefOrGetter, options?: UseFaviconOptions ): ComputedRef export function useFavicon( @@ -26,7 +26,7 @@ export function useFavicon( options?: UseFaviconOptions ): Ref export function useFavicon( - newIcon: MaybeComputedRef = null, + newIcon: MaybeRefOrGetter = null, options: UseFaviconOptions = {}, ) { const { diff --git a/packages/core/useFetch/index.ts b/packages/core/useFetch/index.ts index 36b92351653..f0e5e6cf3c4 100644 --- a/packages/core/useFetch/index.ts +++ b/packages/core/useFetch/index.ts @@ -1,4 +1,4 @@ -import type { EventHookOn, Fn, MaybeComputedRef, Stoppable } from '@vueuse/shared' +import type { EventHookOn, Fn, MaybeRefOrGetter, Stoppable } from '@vueuse/shared' import { containsProp, createEventHook, toRef, toValue, until, useTimeoutFn } from '@vueuse/shared' import type { ComputedRef, Ref } from 'vue-demi' import { computed, isRef, ref, shallowRef, watch } from 'vue-demi' @@ -73,12 +73,12 @@ export interface UseFetchReturn { // methods get(): UseFetchReturn & PromiseLike> - post(payload?: MaybeComputedRef, type?: string): UseFetchReturn & PromiseLike> - put(payload?: MaybeComputedRef, type?: string): UseFetchReturn & PromiseLike> - delete(payload?: MaybeComputedRef, type?: string): UseFetchReturn & PromiseLike> - patch(payload?: MaybeComputedRef, type?: string): UseFetchReturn & PromiseLike> - head(payload?: MaybeComputedRef, type?: string): UseFetchReturn & PromiseLike> - options(payload?: MaybeComputedRef, type?: string): UseFetchReturn & PromiseLike> + post(payload?: MaybeRefOrGetter, type?: string): UseFetchReturn & PromiseLike> + put(payload?: MaybeRefOrGetter, type?: string): UseFetchReturn & PromiseLike> + delete(payload?: MaybeRefOrGetter, type?: string): UseFetchReturn & PromiseLike> + patch(payload?: MaybeRefOrGetter, type?: string): UseFetchReturn & PromiseLike> + head(payload?: MaybeRefOrGetter, type?: string): UseFetchReturn & PromiseLike> + options(payload?: MaybeRefOrGetter, type?: string): UseFetchReturn & PromiseLike> // type json(): UseFetchReturn & PromiseLike> @@ -146,7 +146,7 @@ export interface UseFetchOptions { * * @default false */ - refetch?: MaybeComputedRef + refetch?: MaybeRefOrGetter /** * Initial data before the request finished @@ -185,7 +185,7 @@ export interface CreateFetchOptions { /** * The base URL that will be prefixed to all urls unless urls are absolute */ - baseUrl?: MaybeComputedRef + baseUrl?: MaybeRefOrGetter /** * Determine the inherit behavior for beforeFetch, afterFetch, onFetchError @@ -252,7 +252,7 @@ export function createFetch(config: CreateFetchOptions = {}) { const _options = config.options || {} const _fetchOptions = config.fetchOptions || {} - function useFactoryFetch(url: MaybeComputedRef, ...args: any[]) { + function useFactoryFetch(url: MaybeRefOrGetter, ...args: any[]) { const computedUrl = computed(() => { const baseUrl = toValue(config.baseUrl) const targetUrl = toValue(url) @@ -304,11 +304,11 @@ export function createFetch(config: CreateFetchOptions = {}) { return useFactoryFetch as typeof useFetch } -export function useFetch(url: MaybeComputedRef): UseFetchReturn & PromiseLike> -export function useFetch(url: MaybeComputedRef, useFetchOptions: UseFetchOptions): UseFetchReturn & PromiseLike> -export function useFetch(url: MaybeComputedRef, options: RequestInit, useFetchOptions?: UseFetchOptions): UseFetchReturn & PromiseLike> +export function useFetch(url: MaybeRefOrGetter): UseFetchReturn & PromiseLike> +export function useFetch(url: MaybeRefOrGetter, useFetchOptions: UseFetchOptions): UseFetchReturn & PromiseLike> +export function useFetch(url: MaybeRefOrGetter, options: RequestInit, useFetchOptions?: UseFetchOptions): UseFetchReturn & PromiseLike> -export function useFetch(url: MaybeComputedRef, ...args: any[]): UseFetchReturn & PromiseLike> { +export function useFetch(url: MaybeRefOrGetter, ...args: any[]): UseFetchReturn & PromiseLike> { const supportsAbort = typeof AbortController === 'function' let fetchOptions: RequestInit = {} diff --git a/packages/core/useFileSystemAccess/index.ts b/packages/core/useFileSystemAccess/index.ts index e8169b8850e..b0064b859c4 100644 --- a/packages/core/useFileSystemAccess/index.ts +++ b/packages/core/useFileSystemAccess/index.ts @@ -1,6 +1,6 @@ import type { Ref } from 'vue-demi' import { computed, ref, unref, watch } from 'vue-demi' -import type { Awaitable, MaybeComputedRef } from '@vueuse/shared' +import type { Awaitable, MaybeRefOrGetter } from '@vueuse/shared' import type { ConfigurableWindow } from '../_configurable' import { defaultWindow } from '../_configurable' import { useSupported } from '../useSupported' @@ -85,7 +85,7 @@ export type UseFileSystemAccessOptions = ConfigurableWindow & UseFileSystemAcces /** * file data type */ - dataType?: MaybeComputedRef<'Text' | 'ArrayBuffer' | 'Blob'> + dataType?: MaybeRefOrGetter<'Text' | 'ArrayBuffer' | 'Blob'> } /** diff --git a/packages/core/useImage/index.ts b/packages/core/useImage/index.ts index a0957a41006..74350d3e455 100644 --- a/packages/core/useImage/index.ts +++ b/packages/core/useImage/index.ts @@ -1,5 +1,5 @@ import { watch } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' import type { UseAsyncStateOptions } from '../useAsyncState' import { useAsyncState } from '../useAsyncState' @@ -36,7 +36,7 @@ async function loadImage(options: UseImageOptions): Promise { * @param options Image attributes, as used in the tag * @param asyncStateOptions */ -export function useImage(options: MaybeComputedRef, +export function useImage(options: MaybeRefOrGetter, asyncStateOptions: UseAsyncStateOptions = {}) { const state = useAsyncState( () => loadImage(toValue(options)), diff --git a/packages/core/useInfiniteScroll/index.ts b/packages/core/useInfiniteScroll/index.ts index c237f527637..f14cf0d1695 100644 --- a/packages/core/useInfiniteScroll/index.ts +++ b/packages/core/useInfiniteScroll/index.ts @@ -1,6 +1,6 @@ import type { UnwrapNestedRefs } from 'vue-demi' import { nextTick, reactive, watch } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' import type { UseScrollOptions } from '../useScroll' import { useScroll } from '../useScroll' @@ -34,7 +34,7 @@ export interface UseInfiniteScrollOptions extends UseScrollOptions { * @see https://vueuse.org/useInfiniteScroll */ export function useInfiniteScroll( - element: MaybeComputedRef, + element: MaybeRefOrGetter, onLoadMore: (state: UnwrapNestedRefs>) => void | Promise, options: UseInfiniteScrollOptions = {}, ) { diff --git a/packages/core/useLocalStorage/index.ts b/packages/core/useLocalStorage/index.ts index 1fe375fa455..a551be92f3d 100644 --- a/packages/core/useLocalStorage/index.ts +++ b/packages/core/useLocalStorage/index.ts @@ -1,13 +1,13 @@ -import type { MaybeComputedRef, RemovableRef } from '@vueuse/shared' +import type { MaybeRefOrGetter, RemovableRef } from '@vueuse/shared' import type { UseStorageOptions } from '../useStorage' import { useStorage } from '../useStorage' import { defaultWindow } from '../_configurable' -export function useLocalStorage(key: string, initialValue: MaybeComputedRef, options?: UseStorageOptions): RemovableRef -export function useLocalStorage(key: string, initialValue: MaybeComputedRef, options?: UseStorageOptions): RemovableRef -export function useLocalStorage(key: string, initialValue: MaybeComputedRef, options?: UseStorageOptions): RemovableRef -export function useLocalStorage(key: string, initialValue: MaybeComputedRef, options?: UseStorageOptions): RemovableRef -export function useLocalStorage(key: string, initialValue: MaybeComputedRef, options?: UseStorageOptions): RemovableRef +export function useLocalStorage(key: string, initialValue: MaybeRefOrGetter, options?: UseStorageOptions): RemovableRef +export function useLocalStorage(key: string, initialValue: MaybeRefOrGetter, options?: UseStorageOptions): RemovableRef +export function useLocalStorage(key: string, initialValue: MaybeRefOrGetter, options?: UseStorageOptions): RemovableRef +export function useLocalStorage(key: string, initialValue: MaybeRefOrGetter, options?: UseStorageOptions): RemovableRef +export function useLocalStorage(key: string, initialValue: MaybeRefOrGetter, options?: UseStorageOptions): RemovableRef /** * Reactive LocalStorage. @@ -19,7 +19,7 @@ export function useLocalStorage(key: string, initialValue: MaybeCom */ export function useLocalStorage( key: string, - initialValue: MaybeComputedRef, + initialValue: MaybeRefOrGetter, options: UseStorageOptions = {}, ): RemovableRef { const { window = defaultWindow } = options diff --git a/packages/core/useMagicKeys/index.ts b/packages/core/useMagicKeys/index.ts index 082a4eae884..d2557011f59 100644 --- a/packages/core/useMagicKeys/index.ts +++ b/packages/core/useMagicKeys/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed, reactive, ref, unref } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { noop } from '@vueuse/shared' import { useEventListener } from '../useEventListener' import { defaultWindow } from '../_configurable' @@ -19,7 +19,7 @@ export interface UseMagicKeysOptions { * * @default window */ - target?: MaybeComputedRef + target?: MaybeRefOrGetter /** * Alias map for keys, all the keys should be lowercase diff --git a/packages/core/useMediaControls/index.ts b/packages/core/useMediaControls/index.ts index 2e51538dd89..f3e349f18b1 100644 --- a/packages/core/useMediaControls/index.ts +++ b/packages/core/useMediaControls/index.ts @@ -1,5 +1,5 @@ import { ref, watch, watchEffect } from 'vue-demi' -import type { Fn, MaybeComputedRef, MaybeRef } from '@vueuse/shared' +import type { Fn, MaybeRef, MaybeRefOrGetter } from '@vueuse/shared' import { createEventHook, isNumber, isObject, isString, toValue, tryOnScopeDispose, watchIgnorable } from '@vueuse/shared' import { useEventListener } from '../useEventListener' import type { ConfigurableDocument } from '../_configurable' @@ -58,12 +58,12 @@ interface UseMediaControlsOptions extends ConfigurableDocument { * The source for the media, may either be a string, a `UseMediaSource` object, or a list * of `UseMediaSource` objects. */ - src?: MaybeComputedRef + src?: MaybeRefOrGetter /** * A list of text tracks for the media */ - tracks?: MaybeComputedRef + tracks?: MaybeRefOrGetter } export interface UseMediaTextTrack { @@ -113,7 +113,7 @@ export interface UseMediaTextTrack { /** * Automatically check if the ref exists and if it does run the cb fn */ -function usingElRef(source: MaybeComputedRef, cb: (el: T) => void) { +function usingElRef(source: MaybeRefOrGetter, cb: (el: T) => void) { if (toValue(source)) cb(toValue(source)) } diff --git a/packages/core/useMediaQuery/index.ts b/packages/core/useMediaQuery/index.ts index b775473f926..72c4461a45b 100644 --- a/packages/core/useMediaQuery/index.ts +++ b/packages/core/useMediaQuery/index.ts @@ -1,7 +1,7 @@ /* this implementation is original ported from https://github.com/logaretm/vue-use-web by Abdelrahman Awad */ import { ref, watchEffect } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toRef, tryOnScopeDispose } from '@vueuse/shared' import type { ConfigurableWindow } from '../_configurable' import { defaultWindow } from '../_configurable' @@ -14,7 +14,7 @@ import { useSupported } from '../useSupported' * @param query * @param options */ -export function useMediaQuery(query: MaybeComputedRef, options: ConfigurableWindow = {}) { +export function useMediaQuery(query: MaybeRefOrGetter, options: ConfigurableWindow = {}) { const { window = defaultWindow } = options const isSupported = useSupported(() => window && 'matchMedia' in window && typeof window.matchMedia === 'function') diff --git a/packages/core/useParentElement/index.ts b/packages/core/useParentElement/index.ts index 7fb39df58d9..2c8221f45f7 100644 --- a/packages/core/useParentElement/index.ts +++ b/packages/core/useParentElement/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue, tryOnMounted } from '@vueuse/shared' import type { Ref } from 'vue-demi' import { shallowRef, watch } from 'vue-demi' @@ -6,7 +6,7 @@ import { unrefElement } from '../unrefElement' import { useCurrentElement } from '../useCurrentElement' export function useParentElement( - element: MaybeComputedRef = useCurrentElement(), + element: MaybeRefOrGetter = useCurrentElement(), ): Readonly> { const parentElement = shallowRef() diff --git a/packages/core/usePointerSwipe/index.ts b/packages/core/usePointerSwipe/index.ts index 21bd7245b24..c97cb1803ed 100644 --- a/packages/core/usePointerSwipe/index.ts +++ b/packages/core/usePointerSwipe/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toRef } from '@vueuse/shared' import type { Ref } from 'vue-demi' import { computed, reactive, readonly, ref } from 'vue-demi' @@ -53,7 +53,7 @@ export interface UsePointerSwipeReturn { * @param options */ export function usePointerSwipe( - target: MaybeComputedRef, + target: MaybeRefOrGetter, options: UsePointerSwipeOptions = {}, ): UsePointerSwipeReturn { const targetRef = toRef(target) diff --git a/packages/core/usePrevious/index.ts b/packages/core/usePrevious/index.ts index 5b756ff5358..836be167ec2 100644 --- a/packages/core/usePrevious/index.ts +++ b/packages/core/usePrevious/index.ts @@ -2,7 +2,7 @@ import type { Ref } from 'vue-demi' import { readonly, shallowRef, watch } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toRef } from '@vueuse/shared' /** @@ -10,9 +10,9 @@ import { toRef } from '@vueuse/shared' * * @see {@link https://vueuse.org/usePrevious} */ -export function usePrevious(value: MaybeComputedRef): Readonly> -export function usePrevious(value: MaybeComputedRef, initialValue: T): Readonly> -export function usePrevious(value: MaybeComputedRef, initialValue?: T) { +export function usePrevious(value: MaybeRefOrGetter): Readonly> +export function usePrevious(value: MaybeRefOrGetter, initialValue: T): Readonly> +export function usePrevious(value: MaybeRefOrGetter, initialValue?: T) { const previous = shallowRef(initialValue) watch( diff --git a/packages/core/useScriptTag/index.ts b/packages/core/useScriptTag/index.ts index a1988f9d409..c4c3e13dc9b 100644 --- a/packages/core/useScriptTag/index.ts +++ b/packages/core/useScriptTag/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { noop, toValue, tryOnMounted, tryOnUnmounted } from '@vueuse/shared' import { ref } from 'vue-demi' import type { ConfigurableDocument } from '../_configurable' @@ -55,7 +55,7 @@ export interface UseScriptTagOptions extends ConfigurableDocument { * @param options */ export function useScriptTag( - src: MaybeComputedRef, + src: MaybeRefOrGetter, onLoaded: (el: HTMLScriptElement) => void = noop, options: UseScriptTagOptions = {}, ) { diff --git a/packages/core/useScroll/index.ts b/packages/core/useScroll/index.ts index b9b81c8d9f5..21cee177533 100644 --- a/packages/core/useScroll/index.ts +++ b/packages/core/useScroll/index.ts @@ -1,5 +1,5 @@ import { computed, reactive, ref } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { noop, toValue, useDebounceFn, useThrottleFn } from '@vueuse/shared' import { useEventListener } from '../useEventListener' @@ -55,7 +55,7 @@ export interface UseScrollOptions { * * @default 'auto' */ - behavior?: MaybeComputedRef + behavior?: MaybeRefOrGetter } /** @@ -75,7 +75,7 @@ const ARRIVED_STATE_THRESHOLD_PIXELS = 1 */ export function useScroll( - element: MaybeComputedRef, + element: MaybeRefOrGetter, options: UseScrollOptions = {}, ) { const { diff --git a/packages/core/useScrollLock/index.ts b/packages/core/useScrollLock/index.ts index f4fbfe4a377..99ea798d601 100644 --- a/packages/core/useScrollLock/index.ts +++ b/packages/core/useScrollLock/index.ts @@ -1,5 +1,5 @@ import { computed, ref, watch } from 'vue-demi' -import type { Fn, MaybeComputedRef } from '@vueuse/shared' +import type { Fn, MaybeRefOrGetter } from '@vueuse/shared' import { isIOS, toRef, toValue, tryOnScopeDispose } from '@vueuse/shared' import { useEventListener } from '../useEventListener' @@ -50,7 +50,7 @@ function preventDefault(rawEvent: TouchEvent): boolean { * @param element */ export function useScrollLock( - element: MaybeComputedRef, + element: MaybeRefOrGetter, initialState = false, ) { const isLocked = ref(initialState) diff --git a/packages/core/useSessionStorage/index.ts b/packages/core/useSessionStorage/index.ts index 31d606e751d..fd8c4c3ecf7 100644 --- a/packages/core/useSessionStorage/index.ts +++ b/packages/core/useSessionStorage/index.ts @@ -1,13 +1,13 @@ -import type { MaybeComputedRef, RemovableRef } from '@vueuse/shared' +import type { MaybeRefOrGetter, RemovableRef } from '@vueuse/shared' import type { UseStorageOptions } from '../useStorage' import { useStorage } from '../useStorage' import { defaultWindow } from '../_configurable' -export function useSessionStorage(key: string, initialValue: MaybeComputedRef, options?: UseStorageOptions): RemovableRef -export function useSessionStorage(key: string, initialValue: MaybeComputedRef, options?: UseStorageOptions): RemovableRef -export function useSessionStorage(key: string, initialValue: MaybeComputedRef, options?: UseStorageOptions): RemovableRef -export function useSessionStorage(key: string, initialValue: MaybeComputedRef, options?: UseStorageOptions): RemovableRef -export function useSessionStorage(key: string, initialValue: MaybeComputedRef, options?: UseStorageOptions): RemovableRef +export function useSessionStorage(key: string, initialValue: MaybeRefOrGetter, options?: UseStorageOptions): RemovableRef +export function useSessionStorage(key: string, initialValue: MaybeRefOrGetter, options?: UseStorageOptions): RemovableRef +export function useSessionStorage(key: string, initialValue: MaybeRefOrGetter, options?: UseStorageOptions): RemovableRef +export function useSessionStorage(key: string, initialValue: MaybeRefOrGetter, options?: UseStorageOptions): RemovableRef +export function useSessionStorage(key: string, initialValue: MaybeRefOrGetter, options?: UseStorageOptions): RemovableRef /** * Reactive SessionStorage. @@ -19,7 +19,7 @@ export function useSessionStorage(key: string, initialValue: MaybeC */ export function useSessionStorage( key: string, - initialValue: MaybeComputedRef, + initialValue: MaybeRefOrGetter, options: UseStorageOptions = {}, ): RemovableRef { const { window = defaultWindow } = options diff --git a/packages/core/useShare/index.ts b/packages/core/useShare/index.ts index c2413b5f8a9..48bee8e2af2 100644 --- a/packages/core/useShare/index.ts +++ b/packages/core/useShare/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' import { useSupported } from '../useSupported' import type { ConfigurableNavigator } from '../_configurable' @@ -23,13 +23,13 @@ interface NavigatorWithShare { * @param shareOptions * @param options */ -export function useShare(shareOptions: MaybeComputedRef = {}, options: ConfigurableNavigator = {}) { +export function useShare(shareOptions: MaybeRefOrGetter = {}, options: ConfigurableNavigator = {}) { const { navigator = defaultNavigator } = options const _navigator = (navigator as NavigatorWithShare) const isSupported = useSupported(() => _navigator && 'canShare' in _navigator) - const share = async (overrideOptions: MaybeComputedRef = {}) => { + const share = async (overrideOptions: MaybeRefOrGetter = {}) => { if (isSupported.value) { const data = { ...toValue(shareOptions), diff --git a/packages/core/useSpeechRecognition/index.ts b/packages/core/useSpeechRecognition/index.ts index 9006be75bdf..61697a01b0e 100644 --- a/packages/core/useSpeechRecognition/index.ts +++ b/packages/core/useSpeechRecognition/index.ts @@ -1,7 +1,7 @@ // ported from https://www.reddit.com/r/vuejs/comments/jksizl/speech_recognition_as_a_vue_3_hook // by https://github.com/wobsoriano -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toRef, tryOnScopeDispose } from '@vueuse/shared' import type { Ref } from 'vue-demi' import { ref, shallowRef, unref, watch } from 'vue-demi' @@ -28,7 +28,7 @@ export interface UseSpeechRecognitionOptions extends ConfigurableWindow { * * @default 'en-US' */ - lang?: MaybeComputedRef + lang?: MaybeRefOrGetter } /** diff --git a/packages/core/useSpeechSynthesis/index.ts b/packages/core/useSpeechSynthesis/index.ts index d19b685614c..f7c3ed8a596 100644 --- a/packages/core/useSpeechSynthesis/index.ts +++ b/packages/core/useSpeechSynthesis/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef, MaybeRef } from '@vueuse/shared' +import type { MaybeRef, MaybeRefOrGetter } from '@vueuse/shared' import { toRef, tryOnScopeDispose } from '@vueuse/shared' import type { Ref } from 'vue-demi' import { computed, ref, shallowRef, unref, watch } from 'vue-demi' @@ -14,7 +14,7 @@ export interface UseSpeechSynthesisOptions extends ConfigurableWindow { * * @default 'en-US' */ - lang?: MaybeComputedRef + lang?: MaybeRefOrGetter /** * Gets and sets the pitch at which the utterance will be spoken at. * @@ -46,7 +46,7 @@ export interface UseSpeechSynthesisOptions extends ConfigurableWindow { * @see https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis SpeechSynthesis * @param options */ -export function useSpeechSynthesis(text: MaybeComputedRef, options: UseSpeechSynthesisOptions = {}) { +export function useSpeechSynthesis(text: MaybeRefOrGetter, options: UseSpeechSynthesisOptions = {}) { const { pitch = 1, rate = 1, diff --git a/packages/core/useStorage/index.ts b/packages/core/useStorage/index.ts index 39e00c4f3df..0a74a723e62 100644 --- a/packages/core/useStorage/index.ts +++ b/packages/core/useStorage/index.ts @@ -1,5 +1,5 @@ import { nextTick, ref, shallowRef } from 'vue-demi' -import type { Awaitable, ConfigurableEventFilter, ConfigurableFlush, MaybeComputedRef, RemovableRef } from '@vueuse/shared' +import type { Awaitable, ConfigurableEventFilter, ConfigurableFlush, MaybeRefOrGetter, RemovableRef } from '@vueuse/shared' import { isFunction, pausableWatch, toValue } from '@vueuse/shared' import type { StorageLike } from '../ssr-handlers' import { getSSRHandler } from '../ssr-handlers' @@ -114,11 +114,11 @@ export interface UseStorageOptions extends ConfigurableEventFilter, Configura shallow?: boolean } -export function useStorage(key: string, defaults: MaybeComputedRef, storage?: StorageLike, options?: UseStorageOptions): RemovableRef -export function useStorage(key: string, defaults: MaybeComputedRef, storage?: StorageLike, options?: UseStorageOptions): RemovableRef -export function useStorage(key: string, defaults: MaybeComputedRef, storage?: StorageLike, options?: UseStorageOptions): RemovableRef -export function useStorage(key: string, defaults: MaybeComputedRef, storage?: StorageLike, options?: UseStorageOptions): RemovableRef -export function useStorage(key: string, defaults: MaybeComputedRef, storage?: StorageLike, options?: UseStorageOptions): RemovableRef +export function useStorage(key: string, defaults: MaybeRefOrGetter, storage?: StorageLike, options?: UseStorageOptions): RemovableRef +export function useStorage(key: string, defaults: MaybeRefOrGetter, storage?: StorageLike, options?: UseStorageOptions): RemovableRef +export function useStorage(key: string, defaults: MaybeRefOrGetter, storage?: StorageLike, options?: UseStorageOptions): RemovableRef +export function useStorage(key: string, defaults: MaybeRefOrGetter, storage?: StorageLike, options?: UseStorageOptions): RemovableRef +export function useStorage(key: string, defaults: MaybeRefOrGetter, storage?: StorageLike, options?: UseStorageOptions): RemovableRef /** * Reactive LocalStorage/SessionStorage. @@ -127,7 +127,7 @@ export function useStorage(key: string, defaults: MaybeComputedRef< */ export function useStorage( key: string, - defaults: MaybeComputedRef, + defaults: MaybeRefOrGetter, storage: StorageLike | undefined, options: UseStorageOptions = {}, ): RemovableRef { diff --git a/packages/core/useStorageAsync/index.ts b/packages/core/useStorageAsync/index.ts index e4bcf53ab9a..d1aba2ed8e6 100644 --- a/packages/core/useStorageAsync/index.ts +++ b/packages/core/useStorageAsync/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef, RemovableRef } from '@vueuse/shared' +import type { MaybeRefOrGetter, RemovableRef } from '@vueuse/shared' import { isFunction, toValue, watchWithFilter } from '@vueuse/shared' import type { Ref } from 'vue-demi' import { ref, shallowRef } from 'vue-demi' @@ -17,11 +17,11 @@ export interface UseStorageAsyncOptions extends Omit, 's serializer?: SerializerAsync } -export function useStorageAsync(key: string, initialValue: MaybeComputedRef, storage?: StorageLikeAsync, options?: UseStorageAsyncOptions): RemovableRef -export function useStorageAsync(key: string, initialValue: MaybeComputedRef, storage?: StorageLikeAsync, options?: UseStorageAsyncOptions): RemovableRef -export function useStorageAsync(key: string, initialValue: MaybeComputedRef, storage?: StorageLikeAsync, options?: UseStorageAsyncOptions): RemovableRef -export function useStorageAsync(key: string, initialValue: MaybeComputedRef, storage?: StorageLikeAsync, options?: UseStorageAsyncOptions): RemovableRef -export function useStorageAsync(key: string, initialValue: MaybeComputedRef, storage?: StorageLikeAsync, options?: UseStorageAsyncOptions): RemovableRef +export function useStorageAsync(key: string, initialValue: MaybeRefOrGetter, storage?: StorageLikeAsync, options?: UseStorageAsyncOptions): RemovableRef +export function useStorageAsync(key: string, initialValue: MaybeRefOrGetter, storage?: StorageLikeAsync, options?: UseStorageAsyncOptions): RemovableRef +export function useStorageAsync(key: string, initialValue: MaybeRefOrGetter, storage?: StorageLikeAsync, options?: UseStorageAsyncOptions): RemovableRef +export function useStorageAsync(key: string, initialValue: MaybeRefOrGetter, storage?: StorageLikeAsync, options?: UseStorageAsyncOptions): RemovableRef +export function useStorageAsync(key: string, initialValue: MaybeRefOrGetter, storage?: StorageLikeAsync, options?: UseStorageAsyncOptions): RemovableRef /** * Reactive Storage in with async support. @@ -34,7 +34,7 @@ export function useStorageAsync(key: string, initialValue: MaybeCom */ export function useStorageAsync( key: string, - initialValue: MaybeComputedRef, + initialValue: MaybeRefOrGetter, storage: StorageLikeAsync | undefined, options: UseStorageAsyncOptions = {}, ): RemovableRef { diff --git a/packages/core/useSwipe/index.ts b/packages/core/useSwipe/index.ts index e72800a183c..78808bb2ad8 100644 --- a/packages/core/useSwipe/index.ts +++ b/packages/core/useSwipe/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { noop } from '@vueuse/shared' import type { ComputedRef, Ref } from 'vue-demi' import { computed, reactive, ref } from 'vue-demi' @@ -57,7 +57,7 @@ export interface UseSwipeReturn { * @param options */ export function useSwipe( - target: MaybeComputedRef, + target: MaybeRefOrGetter, options: UseSwipeOptions = {}, ): UseSwipeReturn { const { diff --git a/packages/core/useTimeAgo/index.ts b/packages/core/useTimeAgo/index.ts index ccef13ba505..3f1e99bfb7e 100644 --- a/packages/core/useTimeAgo/index.ts +++ b/packages/core/useTimeAgo/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef, Pausable } from '@vueuse/shared' +import type { MaybeRefOrGetter, Pausable } from '@vueuse/shared' import { toValue } from '@vueuse/shared' import type { ComputedRef } from 'vue-demi' import { computed, unref } from 'vue-demi' @@ -131,9 +131,9 @@ export type UseTimeAgoReturn = Controls extend * @see https://vueuse.org/useTimeAgo * @param options */ -export function useTimeAgo(time: MaybeComputedRef, options?: UseTimeAgoOptions): UseTimeAgoReturn -export function useTimeAgo(time: MaybeComputedRef, options: UseTimeAgoOptions): UseTimeAgoReturn -export function useTimeAgo(time: MaybeComputedRef, options: UseTimeAgoOptions = {}) { +export function useTimeAgo(time: MaybeRefOrGetter, options?: UseTimeAgoOptions): UseTimeAgoReturn +export function useTimeAgo(time: MaybeRefOrGetter, options: UseTimeAgoOptions): UseTimeAgoReturn +export function useTimeAgo(time: MaybeRefOrGetter, options: UseTimeAgoOptions = {}) { const { controls: exposeControls = false, updateInterval = 30_000, diff --git a/packages/core/useTimeoutPoll/index.ts b/packages/core/useTimeoutPoll/index.ts index 3a91dc06036..c2a4bb819d4 100644 --- a/packages/core/useTimeoutPoll/index.ts +++ b/packages/core/useTimeoutPoll/index.ts @@ -1,8 +1,8 @@ import { ref } from 'vue-demi' -import type { Awaitable, MaybeComputedRef, Pausable, UseTimeoutFnOptions } from '@vueuse/shared' +import type { Awaitable, MaybeRefOrGetter, Pausable, UseTimeoutFnOptions } from '@vueuse/shared' import { tryOnScopeDispose, useTimeoutFn } from '@vueuse/shared' -export function useTimeoutPoll(fn: () => Awaitable, interval: MaybeComputedRef, timeoutPollOptions?: UseTimeoutFnOptions): Pausable { +export function useTimeoutPoll(fn: () => Awaitable, interval: MaybeRefOrGetter, timeoutPollOptions?: UseTimeoutFnOptions): Pausable { const { start } = useTimeoutFn(loop, interval) const isActive = ref(false) diff --git a/packages/core/useTitle/index.ts b/packages/core/useTitle/index.ts index d01a77ed29b..62722f0a40f 100644 --- a/packages/core/useTitle/index.ts +++ b/packages/core/useTitle/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef, MaybeReadonlyRef, MaybeRef } from '@vueuse/shared' +import type { MaybeRef, MaybeRefOrGetter } from '@vueuse/shared' import { isFunction, isString, toRef } from '@vueuse/shared' import type { ComputedRef, Ref, WritableComputedRef } from 'vue-demi' import { unref, watch } from 'vue-demi' @@ -29,7 +29,7 @@ export type UseTitleOptionsBase = export type UseTitleOptions = ConfigurableDocument & UseTitleOptionsBase export function useTitle( - newTitle: MaybeReadonlyRef, + newTitle: MaybeRefOrGetter, options?: UseTitleOptions, ): ComputedRef @@ -46,7 +46,7 @@ export function useTitle( * @param options */ export function useTitle( - newTitle: MaybeComputedRef = null, + newTitle: MaybeRefOrGetter = null, options: UseTitleOptions = {}, ) { /* diff --git a/packages/core/useTransition/index.ts b/packages/core/useTransition/index.ts index 674f111a14c..9e0c4cc007f 100644 --- a/packages/core/useTransition/index.ts +++ b/packages/core/useTransition/index.ts @@ -1,7 +1,7 @@ import { computed, ref, unref, watch } from 'vue-demi' import { isFunction, isNumber, identity as linear, promiseTimeout, toValue, tryOnScopeDispose } from '@vueuse/shared' import type { ComputedRef, Ref } from 'vue-demi' -import type { MaybeComputedRef, MaybeRef } from '@vueuse/shared' +import type { MaybeRef, MaybeRefOrGetter } from '@vueuse/shared' /** * Cubic bezier points @@ -186,13 +186,13 @@ export function executeTransition( } // option 1: reactive number -export function useTransition(source: MaybeComputedRef, options?: UseTransitionOptions): ComputedRef +export function useTransition(source: MaybeRefOrGetter, options?: UseTransitionOptions): ComputedRef // option 2: static array of possibly reactive numbers -export function useTransition[]>(source: [...T], options?: UseTransitionOptions): ComputedRef<{ [K in keyof T]: number }> +export function useTransition[]>(source: [...T], options?: UseTransitionOptions): ComputedRef<{ [K in keyof T]: number }> // option 3: reactive array of numbers -export function useTransition>(source: T, options?: UseTransitionOptions): ComputedRef +export function useTransition>(source: T, options?: UseTransitionOptions): ComputedRef /** * Follow value with a transition. @@ -202,7 +202,7 @@ export function useTransition>(source: T, o * @param options */ export function useTransition( - source: MaybeComputedRef | MaybeComputedRef[], + source: MaybeRefOrGetter | MaybeRefOrGetter[], options: UseTransitionOptions = {}, ): Ref { let currentId = 0 diff --git a/packages/core/useVibrate/index.ts b/packages/core/useVibrate/index.ts index c4b0694ec5c..9c9ffd6a9d3 100644 --- a/packages/core/useVibrate/index.ts +++ b/packages/core/useVibrate/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef, Pausable } from '@vueuse/shared' +import type { MaybeRefOrGetter, Pausable } from '@vueuse/shared' import { toRef, useIntervalFn } from '@vueuse/shared' import { useSupported } from '../useSupported' import type { ConfigurableNavigator } from '../_configurable' @@ -18,7 +18,7 @@ export interface UseVibrateOptions extends ConfigurableNavigator { * @default [] * */ - pattern?: MaybeComputedRef + pattern?: MaybeRefOrGetter /** * Interval to run a persistent vibration, in ms * diff --git a/packages/core/useWebSocket/index.ts b/packages/core/useWebSocket/index.ts index 0b74db54f02..905c6edd27a 100644 --- a/packages/core/useWebSocket/index.ts +++ b/packages/core/useWebSocket/index.ts @@ -1,6 +1,6 @@ import type { Ref } from 'vue-demi' import { ref, watch } from 'vue-demi' -import type { Fn, MaybeComputedRef } from '@vueuse/shared' +import type { Fn, MaybeRefOrGetter } from '@vueuse/shared' import { toRef, tryOnScopeDispose, useIntervalFn } from '@vueuse/shared' import { useEventListener } from '../useEventListener' @@ -143,7 +143,7 @@ function resolveNestedOptions(options: T | true): T { * @param url */ export function useWebSocket( - url: MaybeComputedRef, + url: MaybeRefOrGetter, options: UseWebSocketOptions = {}, ): UseWebSocketReturn { const { diff --git a/packages/integrations/useAsyncValidator/index.ts b/packages/integrations/useAsyncValidator/index.ts index 5f90cbf18a7..23ffc019275 100644 --- a/packages/integrations/useAsyncValidator/index.ts +++ b/packages/integrations/useAsyncValidator/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toRef, toValue, until } from '@vueuse/shared' import Schema from 'async-validator' import type { Rules, ValidateError, ValidateOption } from 'async-validator' @@ -54,8 +54,8 @@ export interface UseAsyncValidatorOptions { * @see https://github.com/yiminghe/async-validator */ export function useAsyncValidator( - value: MaybeComputedRef>, - rules: MaybeComputedRef, + value: MaybeRefOrGetter>, + rules: MaybeRefOrGetter, options: UseAsyncValidatorOptions = {}, ): UseAsyncValidatorReturn & PromiseLike { const { diff --git a/packages/integrations/useChangeCase/index.ts b/packages/integrations/useChangeCase/index.ts index 09ef29f06bb..fd82451566f 100644 --- a/packages/integrations/useChangeCase/index.ts +++ b/packages/integrations/useChangeCase/index.ts @@ -1,5 +1,5 @@ import type { Options } from 'change-case' -import type { MaybeComputedRef, MaybeRef } from '@vueuse/shared' +import type { MaybeRef, MaybeRefOrGetter } from '@vueuse/shared' import { isFunction, toValue } from '@vueuse/shared' import type { ComputedRef, WritableComputedRef } from 'vue-demi' import { computed, ref } from 'vue-demi' @@ -8,14 +8,14 @@ import * as changeCase from './changeCase' export type ChangeCaseType = keyof typeof changeCase export function useChangeCase(input: MaybeRef, type: ChangeCaseType, options?: Options | undefined): WritableComputedRef -export function useChangeCase(input: MaybeComputedRef, type: ChangeCaseType, options?: Options | undefined): ComputedRef +export function useChangeCase(input: MaybeRefOrGetter, type: ChangeCaseType, options?: Options | undefined): ComputedRef /** * Reactive wrapper for `change-case` * * @see https://vueuse.org/useChangeCase */ -export function useChangeCase(input: MaybeComputedRef, type: ChangeCaseType, options?: Options | undefined) { +export function useChangeCase(input: MaybeRefOrGetter, type: ChangeCaseType, options?: Options | undefined) { if (isFunction(input)) return computed(() => changeCase[type](toValue(input), options)) diff --git a/packages/integrations/useFuse/index.ts b/packages/integrations/useFuse/index.ts index e3e06eee902..fe4d6787a94 100644 --- a/packages/integrations/useFuse/index.ts +++ b/packages/integrations/useFuse/index.ts @@ -1,7 +1,7 @@ import Fuse from 'fuse.js' import type { ComputedRef } from 'vue-demi' import { computed, ref, unref, watch } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' export type FuseOptions = Fuse.IFuseOptions @@ -12,9 +12,9 @@ export interface UseFuseOptions { } export function useFuse( - search: MaybeComputedRef, - data: MaybeComputedRef, - options?: MaybeComputedRef>, + search: MaybeRefOrGetter, + data: MaybeRefOrGetter, + options?: MaybeRefOrGetter>, ) { const createFuse = () => { return new Fuse( diff --git a/packages/integrations/useIDBKeyval/index.ts b/packages/integrations/useIDBKeyval/index.ts index b85ccb2b9ed..2ed673dc96c 100644 --- a/packages/integrations/useIDBKeyval/index.ts +++ b/packages/integrations/useIDBKeyval/index.ts @@ -1,4 +1,4 @@ -import type { ConfigurableFlush, MaybeComputedRef, RemovableRef } from '@vueuse/shared' +import type { ConfigurableFlush, MaybeRefOrGetter, RemovableRef } from '@vueuse/shared' import { toValue } from '@vueuse/shared' import type { Ref } from 'vue-demi' import { ref, shallowRef, watch } from 'vue-demi' @@ -42,7 +42,7 @@ export interface UseIDBOptions extends ConfigurableFlush { */ export function useIDBKeyval( key: IDBValidKey, - initialValue: MaybeComputedRef, + initialValue: MaybeRefOrGetter, options: UseIDBOptions = {}, ): { data: RemovableRef; isFinished: Ref } { const { diff --git a/packages/integrations/useJwt/index.ts b/packages/integrations/useJwt/index.ts index d0ca5281a64..b8513c9634f 100644 --- a/packages/integrations/useJwt/index.ts +++ b/packages/integrations/useJwt/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' import jwt_decode from 'jwt-decode' import type { JwtDecodeOptions, JwtHeader, JwtPayload } from 'jwt-decode' @@ -35,7 +35,7 @@ export function useJwt< Header extends object = JwtHeader, Fallback = null, >( - encodedJwt: MaybeComputedRef, + encodedJwt: MaybeRefOrGetter, options: UseJwtOptions = {}, ): UseJwtReturn { const { diff --git a/packages/integrations/useNProgress/index.ts b/packages/integrations/useNProgress/index.ts index 7dcc4de428e..0b3930fa1ca 100644 --- a/packages/integrations/useNProgress/index.ts +++ b/packages/integrations/useNProgress/index.ts @@ -1,6 +1,6 @@ import type { NProgressOptions } from 'nprogress' import nprogress from 'nprogress' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { isClient, isNumber, tryOnScopeDispose } from '@vueuse/shared' import { computed, ref, watchEffect } from 'vue-demi' @@ -12,7 +12,7 @@ export type UseNProgressOptions = Partial * @see https://vueuse.org/useNProgress */ export function useNProgress( - currentProgress: MaybeComputedRef = null, + currentProgress: MaybeRefOrGetter = null, options?: UseNProgressOptions, ) { const progress = ref(currentProgress) diff --git a/packages/integrations/useQRCode/index.ts b/packages/integrations/useQRCode/index.ts index 3bc1bba2618..c23dcf37e14 100644 --- a/packages/integrations/useQRCode/index.ts +++ b/packages/integrations/useQRCode/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { isClient, toRef } from '@vueuse/shared' import { ref, watch } from 'vue-demi' import QRCode from 'qrcode' @@ -11,7 +11,7 @@ import QRCode from 'qrcode' * @param options */ export function useQRCode( - text: MaybeComputedRef, + text: MaybeRefOrGetter, options?: QRCode.QRCodeToDataURLOptions, ) { const src = toRef(text) diff --git a/packages/integrations/useSortable/index.ts b/packages/integrations/useSortable/index.ts index d962c71b145..45144419fa1 100644 --- a/packages/integrations/useSortable/index.ts +++ b/packages/integrations/useSortable/index.ts @@ -1,5 +1,5 @@ import { defaultDocument, toValue, tryOnMounted, tryOnScopeDispose, unrefElement } from '@vueuse/core' -import type { ConfigurableDocument, MaybeComputedRef } from '@vueuse/core' +import type { ConfigurableDocument, MaybeRefOrGetter } from '@vueuse/core' import Sortable, { type Options } from 'sortablejs' import { nextTick } from 'vue-demi' @@ -16,9 +16,9 @@ export interface UseSortableReturn { export type UseSortableOptions = Options & ConfigurableDocument -export function useSortable(selector: string, list: MaybeComputedRef, +export function useSortable(selector: string, list: MaybeRefOrGetter, options?: UseSortableOptions): UseSortableReturn -export function useSortable(el: MaybeComputedRef, list: MaybeComputedRef, +export function useSortable(el: MaybeRefOrGetter, list: MaybeRefOrGetter, options?: UseSortableOptions): UseSortableReturn /** * Wrapper for sortablejs. @@ -27,8 +27,8 @@ export function useSortable(el: MaybeComputedRef( - el: MaybeComputedRef | string, - list: MaybeComputedRef, + el: MaybeRefOrGetter | string, + list: MaybeRefOrGetter, options: UseSortableOptions = {}, ): UseSortableReturn { let sortable: Sortable @@ -58,7 +58,7 @@ export function useSortable( } export function moveArrayElement( - list: MaybeComputedRef, + list: MaybeRefOrGetter, from: number, to: number, ): void { diff --git a/packages/math/createGenericProjection/index.ts b/packages/math/createGenericProjection/index.ts index 1066b98c3ad..15c4acbca97 100644 --- a/packages/math/createGenericProjection/index.ts +++ b/packages/math/createGenericProjection/index.ts @@ -1,18 +1,18 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' export type ProjectorFunction = (input: F, from: readonly [F, F], to: readonly [T, T]) => T -export type UseProjection = (input: MaybeComputedRef) => ComputedRef +export type UseProjection = (input: MaybeRefOrGetter) => ComputedRef export function createGenericProjection( - fromDomain: MaybeComputedRef, - toDomain: MaybeComputedRef, + fromDomain: MaybeRefOrGetter, + toDomain: MaybeRefOrGetter, projector: ProjectorFunction, ): UseProjection { - return (input: MaybeComputedRef) => { + return (input: MaybeRefOrGetter) => { return computed(() => projector(toValue(input), toValue(fromDomain), toValue(toDomain))) } } diff --git a/packages/math/createProjection/index.ts b/packages/math/createProjection/index.ts index 1f6842e7d2d..81922832b9b 100644 --- a/packages/math/createProjection/index.ts +++ b/packages/math/createProjection/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { createGenericProjection } from '../createGenericProjection' import type { ProjectorFunction, UseProjection } from '../createGenericProjection' @@ -7,8 +7,8 @@ function defaultNumericProjector(input: number, from: readonly [number, number], } export function createProjection( - fromDomain: MaybeComputedRef, - toDomain: MaybeComputedRef, + fromDomain: MaybeRefOrGetter, + toDomain: MaybeRefOrGetter, projector: ProjectorFunction = defaultNumericProjector, ): UseProjection { return createGenericProjection(fromDomain, toDomain, projector) diff --git a/packages/math/logicAnd/index.ts b/packages/math/logicAnd/index.ts index 2a94a44eb59..bbbe88d2e5e 100644 --- a/packages/math/logicAnd/index.ts +++ b/packages/math/logicAnd/index.ts @@ -1,14 +1,14 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' import { toValue } from '@vueuse/shared' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' /** * `AND` conditions for refs. * * @see https://vueuse.org/logicAnd */ -export function logicAnd(...args: MaybeComputedRef[]): ComputedRef { +export function logicAnd(...args: MaybeRefOrGetter[]): ComputedRef { return computed(() => args.every(i => toValue(i))) } diff --git a/packages/math/logicNot/index.ts b/packages/math/logicNot/index.ts index 70032b507ff..46ffb8851de 100644 --- a/packages/math/logicNot/index.ts +++ b/packages/math/logicNot/index.ts @@ -1,14 +1,14 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' import { toValue } from '@vueuse/shared' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' /** * `NOT` conditions for refs. * * @see https://vueuse.org/logicNot */ -export function logicNot(v: MaybeComputedRef): ComputedRef { +export function logicNot(v: MaybeRefOrGetter): ComputedRef { return computed(() => !toValue(v)) } diff --git a/packages/math/logicOr/index.ts b/packages/math/logicOr/index.ts index 869ddb730a0..cf8a3abd5c4 100644 --- a/packages/math/logicOr/index.ts +++ b/packages/math/logicOr/index.ts @@ -1,14 +1,14 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' import { toValue } from '@vueuse/shared' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' /** * `OR` conditions for refs. * * @see https://vueuse.org/logicOr */ -export function logicOr(...args: MaybeComputedRef[]): ComputedRef { +export function logicOr(...args: MaybeRefOrGetter[]): ComputedRef { return computed(() => args.some(i => toValue(i))) } diff --git a/packages/math/useAbs/index.ts b/packages/math/useAbs/index.ts index 77a229148d2..4c8303495bf 100644 --- a/packages/math/useAbs/index.ts +++ b/packages/math/useAbs/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' @@ -8,6 +8,6 @@ import { computed } from 'vue-demi' * * @see https://vueuse.org/useAbs */ -export function useAbs(value: MaybeComputedRef): ComputedRef { +export function useAbs(value: MaybeRefOrGetter): ComputedRef { return computed(() => Math.abs(toValue(value))) } diff --git a/packages/math/useAverage/index.ts b/packages/math/useAverage/index.ts index fb131525286..1ff45f37ad8 100644 --- a/packages/math/useAverage/index.ts +++ b/packages/math/useAverage/index.ts @@ -1,11 +1,11 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import type { MaybeComputedRefArgs } from '../utils' import { toValueArgsFlat } from '../utils' -export function useAverage(array: MaybeComputedRef[]>): ComputedRef -export function useAverage(...args: MaybeComputedRef[]): ComputedRef +export function useAverage(array: MaybeRefOrGetter[]>): ComputedRef +export function useAverage(...args: MaybeRefOrGetter[]): ComputedRef /** * Get the average of an array reactively diff --git a/packages/math/useCeil/index.ts b/packages/math/useCeil/index.ts index a44a687905b..a3aead6c0cf 100644 --- a/packages/math/useCeil/index.ts +++ b/packages/math/useCeil/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' /** @@ -8,6 +8,6 @@ import { toValue } from '@vueuse/shared' * * @see https://vueuse.org/useCeil */ -export function useCeil(value: MaybeComputedRef): ComputedRef { +export function useCeil(value: MaybeRefOrGetter): ComputedRef { return computed(() => Math.ceil(toValue(value))) } diff --git a/packages/math/useClamp/index.ts b/packages/math/useClamp/index.ts index 6ffde5354cf..fc027c47525 100644 --- a/packages/math/useClamp/index.ts +++ b/packages/math/useClamp/index.ts @@ -1,18 +1,18 @@ import type { ComputedRef, Ref } from 'vue-demi' import { computed, isReadonly, ref } from 'vue-demi' -import type { MaybeComputedRef, MaybeReadonlyRef, MaybeRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { clamp, isFunction, toValue } from '@vueuse/shared' export function useClamp( - value: MaybeReadonlyRef, - min: MaybeComputedRef, - max: MaybeComputedRef, + value: MaybeRefOrGetter, + min: MaybeRefOrGetter, + max: MaybeRefOrGetter, ): ComputedRef export function useClamp( - value: MaybeRef, - min: MaybeComputedRef, - max: MaybeComputedRef, + value: MaybeRefOrGetter, + min: MaybeRefOrGetter, + max: MaybeRefOrGetter, ): Ref /** @@ -23,7 +23,7 @@ export function useClamp( * @param min * @param max */ -export function useClamp(value: MaybeComputedRef, min: MaybeComputedRef, max: MaybeComputedRef) { +export function useClamp(value: MaybeRefOrGetter, min: MaybeRefOrGetter, max: MaybeRefOrGetter) { if (isFunction(value) || isReadonly(value)) return computed(() => clamp(toValue(value), toValue(min), toValue(max))) diff --git a/packages/math/useFloor/index.ts b/packages/math/useFloor/index.ts index 14876cdf054..f6542a1d332 100644 --- a/packages/math/useFloor/index.ts +++ b/packages/math/useFloor/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' /** @@ -8,6 +8,6 @@ import { toValue } from '@vueuse/shared' * * @see https://vueuse.org/useFloor */ -export function useFloor(value: MaybeComputedRef): ComputedRef { +export function useFloor(value: MaybeRefOrGetter): ComputedRef { return computed(() => Math.floor(toValue(value))) } diff --git a/packages/math/useMax/index.ts b/packages/math/useMax/index.ts index fbfd12d8d38..effa2eb2a24 100644 --- a/packages/math/useMax/index.ts +++ b/packages/math/useMax/index.ts @@ -1,11 +1,11 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import type { MaybeComputedRefArgs } from '../utils' import { toValueArgsFlat } from '../utils' -export function useMax(array: MaybeComputedRef[]>): ComputedRef -export function useMax(...args: MaybeComputedRef[]): ComputedRef +export function useMax(array: MaybeRefOrGetter[]>): ComputedRef +export function useMax(...args: MaybeRefOrGetter[]): ComputedRef /** * Reactively get maximum of values. diff --git a/packages/math/useMin/index.ts b/packages/math/useMin/index.ts index a3b75e78982..a130fbef5b4 100644 --- a/packages/math/useMin/index.ts +++ b/packages/math/useMin/index.ts @@ -1,11 +1,11 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import type { MaybeComputedRefArgs } from '../utils' import { toValueArgsFlat } from '../utils' -export function useMin(array: MaybeComputedRef[]>): ComputedRef -export function useMin(...args: MaybeComputedRef[]): ComputedRef +export function useMin(array: MaybeRefOrGetter[]>): ComputedRef +export function useMin(...args: MaybeRefOrGetter[]): ComputedRef /** * Reactive `Math.min`. diff --git a/packages/math/usePrecision/index.ts b/packages/math/usePrecision/index.ts index cc0ec972aff..9ff3ba9f35a 100644 --- a/packages/math/usePrecision/index.ts +++ b/packages/math/usePrecision/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' export interface UsePrecisionOptions { @@ -18,9 +18,9 @@ export interface UsePrecisionOptions { * @see https://vueuse.org/usePrecision */ export function usePrecision( - value: MaybeComputedRef, - digits: MaybeComputedRef, - options?: MaybeComputedRef, + value: MaybeRefOrGetter, + digits: MaybeRefOrGetter, + options?: MaybeRefOrGetter, ): ComputedRef { return computed(() => { const _value = toValue(value) diff --git a/packages/math/useProjection/index.ts b/packages/math/useProjection/index.ts index 0cf02799e88..17d9aa9bb83 100644 --- a/packages/math/useProjection/index.ts +++ b/packages/math/useProjection/index.ts @@ -1,4 +1,4 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import type { ProjectorFunction } from '../createGenericProjection' import { createProjection } from '../createProjection' @@ -8,9 +8,9 @@ import { createProjection } from '../createProjection' * @see https://vueuse.org/useProjection */ export function useProjection( - input: MaybeComputedRef, - fromDomain: MaybeComputedRef, - toDomain: MaybeComputedRef, + input: MaybeRefOrGetter, + fromDomain: MaybeRefOrGetter, + toDomain: MaybeRefOrGetter, projector?: ProjectorFunction, ) { return createProjection(fromDomain, toDomain, projector)(input) diff --git a/packages/math/useRound/index.ts b/packages/math/useRound/index.ts index bbe9c748144..74c2a88a081 100644 --- a/packages/math/useRound/index.ts +++ b/packages/math/useRound/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' /** @@ -8,6 +8,6 @@ import { toValue } from '@vueuse/shared' * * @see https://vueuse.org/useRound */ -export function useRound(value: MaybeComputedRef): ComputedRef { +export function useRound(value: MaybeRefOrGetter): ComputedRef { return computed(() => Math.round(toValue(value))) } diff --git a/packages/math/useSum/index.ts b/packages/math/useSum/index.ts index 3335247a3b6..e9ebc966d87 100644 --- a/packages/math/useSum/index.ts +++ b/packages/math/useSum/index.ts @@ -1,11 +1,11 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import type { MaybeComputedRefArgs } from '../utils' import { toValueArgsFlat } from '../utils' -export function useSum(array: MaybeComputedRef[]>): ComputedRef -export function useSum(...args: MaybeComputedRef[]): ComputedRef +export function useSum(array: MaybeRefOrGetter[]>): ComputedRef +export function useSum(...args: MaybeRefOrGetter[]): ComputedRef /** * Get the sum of a set of numbers. diff --git a/packages/math/useTrunc/index.ts b/packages/math/useTrunc/index.ts index 34ef17e2673..11a2804dc8c 100644 --- a/packages/math/useTrunc/index.ts +++ b/packages/math/useTrunc/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' /** @@ -8,6 +8,6 @@ import { toValue } from '@vueuse/shared' * * @see https://vueuse.org/useTrunc */ -export function useTrunc(value: MaybeComputedRef): ComputedRef { +export function useTrunc(value: MaybeRefOrGetter): ComputedRef { return computed(() => Math.trunc(toValue(value))) } diff --git a/packages/math/utils.ts b/packages/math/utils.ts index 3611ef4deb9..7bda28ec308 100644 --- a/packages/math/utils.ts +++ b/packages/math/utils.ts @@ -1,7 +1,7 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { MaybeRefOrGetter } from '@vueuse/shared' import { toValue } from '@vueuse/shared' -export type MaybeComputedRefArgs = MaybeComputedRef[] | [MaybeComputedRef[]>] +export type MaybeComputedRefArgs = MaybeRefOrGetter[] | [MaybeRefOrGetter[]>] export function toValueArgsFlat(args: MaybeComputedRefArgs): T[] { return args diff --git a/packages/shared/reactify/index.ts b/packages/shared/reactify/index.ts index ac97d67f616..a0d8c57ee8a 100644 --- a/packages/shared/reactify/index.ts +++ b/packages/shared/reactify/index.ts @@ -1,10 +1,10 @@ import type { ComputedRef } from 'vue-demi' import { computed, unref } from 'vue-demi' import { toValue } from '../toValue' -import type { MaybeComputedRef, MaybeRef } from '../utils' +import type { MaybeRef, MaybeRefOrGetter } from '../utils' export type Reactified = T extends (...args: infer A) => infer R - ? (...args: { [K in keyof A]: Computed extends true ? MaybeComputedRef : MaybeRef }) => ComputedRef + ? (...args: { [K in keyof A]: Computed extends true ? MaybeRefOrGetter : MaybeRef }) => ComputedRef : never export interface ReactifyOptions { diff --git a/packages/shared/refAutoReset/index.ts b/packages/shared/refAutoReset/index.ts index 88f625f57d5..aaf91e404f5 100644 --- a/packages/shared/refAutoReset/index.ts +++ b/packages/shared/refAutoReset/index.ts @@ -1,6 +1,6 @@ import type { Ref } from 'vue-demi' import { customRef } from 'vue-demi' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' import { toValue } from '../toValue' import { tryOnScopeDispose } from '../tryOnScopeDispose' @@ -11,7 +11,7 @@ import { tryOnScopeDispose } from '../tryOnScopeDispose' * @param defaultValue The value which will be set. * @param afterMs A zero-or-greater delay in milliseconds. */ -export function refAutoReset(defaultValue: T, afterMs: MaybeComputedRef = 10000): Ref { +export function refAutoReset(defaultValue: T, afterMs: MaybeRefOrGetter = 10000): Ref { return customRef((track, trigger) => { let value: T = defaultValue let timer: any diff --git a/packages/shared/refDebounced/index.ts b/packages/shared/refDebounced/index.ts index 4050edb89cf..aad87815754 100644 --- a/packages/shared/refDebounced/index.ts +++ b/packages/shared/refDebounced/index.ts @@ -1,14 +1,14 @@ import type { Ref } from 'vue-demi' import { ref, watch } from 'vue-demi' import { useDebounceFn } from '../useDebounceFn' -import type { DebounceFilterOptions, MaybeComputedRef } from '../utils' +import type { DebounceFilterOptions, MaybeRefOrGetter } from '../utils' /** * Debounce updates of a ref. * * @return A new debounced ref. */ -export function refDebounced(value: Ref, ms: MaybeComputedRef = 200, options: DebounceFilterOptions = {}): Readonly> { +export function refDebounced(value: Ref, ms: MaybeRefOrGetter = 200, options: DebounceFilterOptions = {}): Readonly> { const debounced = ref(value.value as T) as Ref const updater = useDebounceFn(() => { diff --git a/packages/shared/toRef/index.ts b/packages/shared/toRef/index.ts index 43231bade3e..0bc0969d7b7 100644 --- a/packages/shared/toRef/index.ts +++ b/packages/shared/toRef/index.ts @@ -1,13 +1,12 @@ -import type { ComputedRef, Ref, ToRef } from 'vue-demi' -import { customRef, ref, toRef as vueToRef } from 'vue-demi' -import type { MaybeComputedRef, MaybeRef } from '../utils' +import type { Ref, ToRef } from 'vue-demi' +import { customRef, readonly, ref, toRef as vueToRef } from 'vue-demi' +import type { MaybeRefOrGetter } from '../utils' import { noop } from '../utils' /** * Normalize value/ref/getter to `ref` or `computed`. */ -export function toRef(r: MaybeComputedRef): ComputedRef -export function toRef(r: MaybeRef): Ref +export function toRef(r: MaybeRefOrGetter): Ref export function toRef(r: T): Ref export function toRef(object: T, key: K): ToRef export function toRef(object: T, key: K, defaultValue: T[K]): ToRef> @@ -16,7 +15,7 @@ export function toRef(...args: any[]) { return vueToRef(...args as [any, any]) const r = args[0] return typeof r === 'function' - ? customRef(() => ({ get: r as any, set: noop })) + ? readonly(customRef(() => ({ get: r as any, set: noop }))) : ref(r) } diff --git a/packages/shared/toValue/index.ts b/packages/shared/toValue/index.ts index 9d68dd92d04..8b7af2b5924 100644 --- a/packages/shared/toValue/index.ts +++ b/packages/shared/toValue/index.ts @@ -1,10 +1,10 @@ import { unref } from 'vue-demi' -import type { AnyFn, MaybeComputedRef } from '../utils' +import type { AnyFn, MaybeRefOrGetter } from '../utils' /** * Get the value of value/ref/getter. */ -export function toValue(r: MaybeComputedRef): T { +export function toValue(r: MaybeRefOrGetter): T { return typeof r === 'function' ? (r as AnyFn)() : unref(r) diff --git a/packages/shared/until/index.ts b/packages/shared/until/index.ts index da85313f402..5b2e893af58 100644 --- a/packages/shared/until/index.ts +++ b/packages/shared/until/index.ts @@ -1,7 +1,7 @@ import type { WatchOptions, WatchSource } from 'vue-demi' import { isRef, watch } from 'vue-demi' import { toValue } from '../toValue' -import type { ElementOf, MaybeComputedRef, ShallowUnwrapRef } from '../utils' +import type { ElementOf, MaybeRefOrGetter, ShallowUnwrapRef } from '../utils' import { promiseTimeout } from '../utils' export interface UntilToMatchOptions { @@ -53,7 +53,7 @@ type Falsy = false | void | null | undefined | 0 | 0n | '' export interface UntilValueInstance extends UntilBaseInstance { readonly not: UntilValueInstance - toBe

(value: MaybeComputedRef

, options?: UntilToMatchOptions): Not extends true ? Promise : Promise

+ toBe

(value: MaybeRefOrGetter

, options?: UntilToMatchOptions): Not extends true ? Promise : Promise

toBeTruthy(options?: UntilToMatchOptions): Not extends true ? Promise : Promise> toBeNull(options?: UntilToMatchOptions): Not extends true ? Promise> : Promise toBeUndefined(options?: UntilToMatchOptions): Not extends true ? Promise> : Promise @@ -63,7 +63,7 @@ export interface UntilValueInstance extends Unti export interface UntilArrayInstance extends UntilBaseInstance { readonly not: UntilArrayInstance - toContains(value: MaybeComputedRef>>, options?: UntilToMatchOptions): Promise + toContains(value: MaybeRefOrGetter>>, options?: UntilToMatchOptions): Promise } function createUntil(r: any, isNot = false) { @@ -101,7 +101,7 @@ function createUntil(r: any, isNot = false) { return Promise.race(promises) } - function toBe

(value: MaybeComputedRef

, options?: UntilToMatchOptions) { + function toBe

(value: MaybeRefOrGetter

, options?: UntilToMatchOptions) { if (!isRef(value)) return toMatch(v => v === value, options) @@ -221,8 +221,8 @@ function createUntil(r: any, isNot = false) { * alert('Counter is now larger than 7!') * ``` */ -export function until(r: WatchSource | MaybeComputedRef): UntilArrayInstance -export function until(r: WatchSource | MaybeComputedRef): UntilValueInstance +export function until(r: WatchSource | MaybeRefOrGetter): UntilArrayInstance +export function until(r: WatchSource | MaybeRefOrGetter): UntilValueInstance export function until(r: any): UntilValueInstance | UntilArrayInstance { return createUntil(r) } diff --git a/packages/shared/useArrayDifference/index.ts b/packages/shared/useArrayDifference/index.ts index 845802da08a..5ada5c07e3c 100644 --- a/packages/shared/useArrayDifference/index.ts +++ b/packages/shared/useArrayDifference/index.ts @@ -1,15 +1,15 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' import { isString } from '../utils' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' import { toValue } from '../toValue' function defaultComparator(value: T, othVal: T) { return value === othVal } -export function useArrayDifference(list: MaybeComputedRef, values: MaybeComputedRef, key?: keyof T): ComputedRef -export function useArrayDifference(list: MaybeComputedRef, values: MaybeComputedRef, compareFn?: (value: T, othVal: T) => boolean): ComputedRef +export function useArrayDifference(list: MaybeRefOrGetter, values: MaybeRefOrGetter, key?: keyof T): ComputedRef +export function useArrayDifference(list: MaybeRefOrGetter, values: MaybeRefOrGetter, compareFn?: (value: T, othVal: T) => boolean): ComputedRef /** * Reactive get array difference of two array @@ -18,8 +18,8 @@ export function useArrayDifference(list: MaybeComputedRef, values: Maybe * @param args */ export function useArrayDifference(...args: any[]): ComputedRef { - const list: MaybeComputedRef = args[0] - const values: MaybeComputedRef = args[1] + const list: MaybeRefOrGetter = args[0] + const values: MaybeRefOrGetter = args[1] let compareFn = args[2] ?? defaultComparator if (isString(compareFn)) { diff --git a/packages/shared/useArrayEvery/index.ts b/packages/shared/useArrayEvery/index.ts index 92b8a920c34..c000f0d52d1 100644 --- a/packages/shared/useArrayEvery/index.ts +++ b/packages/shared/useArrayEvery/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' import { toValue } from '../toValue' /** @@ -13,8 +13,8 @@ import { toValue } from '../toValue' * @returns {boolean} **true** if the `fn` function returns a **truthy** value for every element from the array. Otherwise, **false**. */ export function useArrayEvery( - list: MaybeComputedRef[]>, - fn: (element: T, index: number, array: MaybeComputedRef[]) => unknown, + list: MaybeRefOrGetter[]>, + fn: (element: T, index: number, array: MaybeRefOrGetter[]) => unknown, ): ComputedRef { return computed(() => toValue(list).every((element, index, array) => fn(toValue(element), index, array))) } diff --git a/packages/shared/useArrayFilter/index.ts b/packages/shared/useArrayFilter/index.ts index 4cb469fd6f5..5a3bc6bf41d 100644 --- a/packages/shared/useArrayFilter/index.ts +++ b/packages/shared/useArrayFilter/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' import { toValue } from '../toValue' /** @@ -13,7 +13,7 @@ import { toValue } from '../toValue' * @returns {Array} a shallow copy of a portion of the given array, filtered down to just the elements from the given array that pass the test implemented by the provided function. If no elements pass the test, an empty array will be returned. */ export function useArrayFilter( - list: MaybeComputedRef[]>, + list: MaybeRefOrGetter[]>, fn: (element: T, index: number, array: T[]) => boolean, ): ComputedRef { return computed(() => toValue(list).map(i => toValue(i)).filter(fn)) diff --git a/packages/shared/useArrayFind/index.ts b/packages/shared/useArrayFind/index.ts index aef1ee11c41..3ebe45c9ab2 100644 --- a/packages/shared/useArrayFind/index.ts +++ b/packages/shared/useArrayFind/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' import { toValue } from '../toValue' /** @@ -13,8 +13,8 @@ import { toValue } from '../toValue' * @returns the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned. */ export function useArrayFind( - list: MaybeComputedRef[]>, - fn: (element: T, index: number, array: MaybeComputedRef[]) => boolean, + list: MaybeRefOrGetter[]>, + fn: (element: T, index: number, array: MaybeRefOrGetter[]) => boolean, ): ComputedRef { return computed(() => toValue( diff --git a/packages/shared/useArrayFindIndex/index.ts b/packages/shared/useArrayFindIndex/index.ts index 4a52164bad3..fbbb2600791 100644 --- a/packages/shared/useArrayFindIndex/index.ts +++ b/packages/shared/useArrayFindIndex/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' import { toValue } from '../toValue' /** @@ -13,8 +13,8 @@ import { toValue } from '../toValue' * @returns {number} the index of the first element in the array that passes the test. Otherwise, "-1". */ export function useArrayFindIndex( - list: MaybeComputedRef[]>, - fn: (element: T, index: number, array: MaybeComputedRef[]) => unknown, + list: MaybeRefOrGetter[]>, + fn: (element: T, index: number, array: MaybeRefOrGetter[]) => unknown, ): ComputedRef { return computed(() => toValue(list).findIndex((element, index, array) => fn(toValue(element), index, array))) } diff --git a/packages/shared/useArrayFindLast/index.ts b/packages/shared/useArrayFindLast/index.ts index a4ec80cac62..25b99ad30db 100644 --- a/packages/shared/useArrayFindLast/index.ts +++ b/packages/shared/useArrayFindLast/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' import { toValue } from '../toValue' // Polyfill for node version < 18 @@ -23,8 +23,8 @@ function findLast(arr: T[], cb: (element: T, index: number, array: T[]) => bo * @returns the last element in the array that satisfies the provided testing function. Otherwise, undefined is returned. */ export function useArrayFindLast( - list: MaybeComputedRef[]>, - fn: (element: T, index: number, array: MaybeComputedRef[]) => boolean, + list: MaybeRefOrGetter[]>, + fn: (element: T, index: number, array: MaybeRefOrGetter[]) => boolean, ): ComputedRef { return computed(() => toValue( diff --git a/packages/shared/useArrayIncludes/index.ts b/packages/shared/useArrayIncludes/index.ts index 9af8cae8687..d13ef44c211 100644 --- a/packages/shared/useArrayIncludes/index.ts +++ b/packages/shared/useArrayIncludes/index.ts @@ -1,10 +1,10 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' import { containsProp, isObject } from '../utils' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' import { toValue } from '../toValue' -export type UseArrayIncludesComparatorFn = ((element: T, value: V, index: number, array: MaybeComputedRef[]) => boolean) +export type UseArrayIncludesComparatorFn = ((element: T, value: V, index: number, array: MaybeRefOrGetter[]) => boolean) function isArrayIncludesOptions(obj: any): obj is UseArrayIncludesOptions { return isObject(obj) && containsProp(obj, 'formIndex', 'comparator') @@ -16,18 +16,18 @@ export interface UseArrayIncludesOptions { } export function useArrayIncludes( - list: MaybeComputedRef[]>, - value: MaybeComputedRef, + list: MaybeRefOrGetter[]>, + value: MaybeRefOrGetter, comparator?: UseArrayIncludesComparatorFn, ): ComputedRef export function useArrayIncludes( - list: MaybeComputedRef[]>, - value: MaybeComputedRef, + list: MaybeRefOrGetter[]>, + value: MaybeRefOrGetter, comparator?: keyof T, ): ComputedRef export function useArrayIncludes( - list: MaybeComputedRef[]>, - value: MaybeComputedRef, + list: MaybeRefOrGetter[]>, + value: MaybeRefOrGetter, options?: UseArrayIncludesOptions, ): ComputedRef /** @@ -41,8 +41,8 @@ export function useArrayIncludes( export function useArrayIncludes( ...args: any[] ): ComputedRef { - const list: MaybeComputedRef[]> = args[0] - const value: MaybeComputedRef = args[1] + const list: MaybeRefOrGetter[]> = args[0] + const value: MaybeRefOrGetter = args[1] let comparator: UseArrayIncludesComparatorFn = args[2] let formIndex = 0 diff --git a/packages/shared/useArrayJoin/index.ts b/packages/shared/useArrayJoin/index.ts index 404368b8fea..36dd27fe130 100644 --- a/packages/shared/useArrayJoin/index.ts +++ b/packages/shared/useArrayJoin/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' import { toValue } from '../toValue' /** @@ -13,8 +13,8 @@ import { toValue } from '../toValue' * @returns {string} a string with all array elements joined. If arr.length is 0, the empty string is returned. */ export function useArrayJoin( - list: MaybeComputedRef[]>, - separator?: MaybeComputedRef, + list: MaybeRefOrGetter[]>, + separator?: MaybeRefOrGetter, ): ComputedRef { return computed(() => toValue(list).map(i => toValue(i)).join(toValue(separator))) } diff --git a/packages/shared/useArrayMap/index.ts b/packages/shared/useArrayMap/index.ts index 024155c73ac..341fbba5308 100644 --- a/packages/shared/useArrayMap/index.ts +++ b/packages/shared/useArrayMap/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' import { toValue } from '../toValue' /** @@ -13,7 +13,7 @@ import { toValue } from '../toValue' * @returns {Array} a new array with each element being the result of the callback function. */ export function useArrayMap( - list: MaybeComputedRef[]>, + list: MaybeRefOrGetter[]>, fn: (element: T, index: number, array: T[]) => U, ): ComputedRef { return computed(() => toValue(list).map(i => toValue(i)).map(fn)) diff --git a/packages/shared/useArrayReduce/index.ts b/packages/shared/useArrayReduce/index.ts index 389f8d42917..1e5c065f9dd 100644 --- a/packages/shared/useArrayReduce/index.ts +++ b/packages/shared/useArrayReduce/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' import { toValue } from '../toValue' export type UseArrayReducer = (previousValue: PV, currentValue: CV, currentIndex: number) => R @@ -15,7 +15,7 @@ export type UseArrayReducer = (previousValue: PV, currentValue: CV, c * @returns the value that results from running the "reducer" callback function to completion over the entire array. */ export function useArrayReduce( - list: MaybeComputedRef[]>, + list: MaybeRefOrGetter[]>, reducer: UseArrayReducer, ): ComputedRef @@ -30,9 +30,9 @@ export function useArrayReduce( * @returns the value that results from running the "reducer" callback function to completion over the entire array. */ export function useArrayReduce( - list: MaybeComputedRef[]>, + list: MaybeRefOrGetter[]>, reducer: UseArrayReducer, - initialValue: MaybeComputedRef, + initialValue: MaybeRefOrGetter, ): ComputedRef /** @@ -46,7 +46,7 @@ export function useArrayReduce( * @returns the value that results from running the "reducer" callback function to completion over the entire array. */ export function useArrayReduce( - list: MaybeComputedRef[]>, + list: MaybeRefOrGetter[]>, reducer: ((...p: any[]) => any), ...args: any[] ): ComputedRef { diff --git a/packages/shared/useArraySome/index.ts b/packages/shared/useArraySome/index.ts index 5edc2354662..1fd3b8201a4 100644 --- a/packages/shared/useArraySome/index.ts +++ b/packages/shared/useArraySome/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' import { toValue } from '../toValue' /** @@ -13,8 +13,8 @@ import { toValue } from '../toValue' * @returns {boolean} **true** if the `fn` function returns a **truthy** value for any element from the array. Otherwise, **false**. */ export function useArraySome( - list: MaybeComputedRef[]>, - fn: (element: T, index: number, array: MaybeComputedRef[]) => unknown, + list: MaybeRefOrGetter[]>, + fn: (element: T, index: number, array: MaybeRefOrGetter[]) => unknown, ): ComputedRef { return computed(() => toValue(list).some((element, index, array) => fn(toValue(element), index, array))) } diff --git a/packages/shared/useArrayUnique/index.ts b/packages/shared/useArrayUnique/index.ts index d3cefeaa8ca..c669b0bd38a 100644 --- a/packages/shared/useArrayUnique/index.ts +++ b/packages/shared/useArrayUnique/index.ts @@ -1,6 +1,6 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' import { toValue } from '../toValue' function uniq(array: T[]) { @@ -26,7 +26,7 @@ function uniqueElementsBy( * @returns {Array} A computed ref that returns a unique array of items. */ export function useArrayUnique( - list: MaybeComputedRef[]>, compareFn?: (a: T, b: T, array: T[]) => boolean): ComputedRef { + list: MaybeRefOrGetter[]>, compareFn?: (a: T, b: T, array: T[]) => boolean): ComputedRef { return computed(() => { const resolvedList = toValue(list).map(element => toValue(element)) return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList) diff --git a/packages/shared/useDateFormat/index.ts b/packages/shared/useDateFormat/index.ts index 07bb7c61fe0..a668ed7ca33 100644 --- a/packages/shared/useDateFormat/index.ts +++ b/packages/shared/useDateFormat/index.ts @@ -1,5 +1,5 @@ import { computed } from 'vue-demi' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' import { toValue } from '../toValue' export type DateLike = Date | number | string | undefined @@ -98,7 +98,7 @@ export function normalizeDate(date: DateLike) { * @param options - UseDateFormatOptions */ -export function useDateFormat(date: MaybeComputedRef, formatStr: MaybeComputedRef = 'HH:mm:ss', options: UseDateFormatOptions = {}) { +export function useDateFormat(date: MaybeRefOrGetter, formatStr: MaybeRefOrGetter = 'HH:mm:ss', options: UseDateFormatOptions = {}) { return computed(() => formatDate(normalizeDate(toValue(date)), toValue(formatStr), options)) } diff --git a/packages/shared/useDebounceFn/index.ts b/packages/shared/useDebounceFn/index.ts index b8e333cc383..b1979cbe484 100644 --- a/packages/shared/useDebounceFn/index.ts +++ b/packages/shared/useDebounceFn/index.ts @@ -1,4 +1,4 @@ -import type { DebounceFilterOptions, FunctionArgs, MaybeComputedRef, PromisifyFn } from '../utils' +import type { DebounceFilterOptions, FunctionArgs, MaybeRefOrGetter, PromisifyFn } from '../utils' import { createFilterWrapper, debounceFilter } from '../utils' /** @@ -13,7 +13,7 @@ import { createFilterWrapper, debounceFilter } from '../utils' */ export function useDebounceFn( fn: T, - ms: MaybeComputedRef = 200, + ms: MaybeRefOrGetter = 200, options: DebounceFilterOptions = {}, ): PromisifyFn { return createFilterWrapper( diff --git a/packages/shared/useInterval/index.ts b/packages/shared/useInterval/index.ts index 211165fd07a..4d13bc7763d 100644 --- a/packages/shared/useInterval/index.ts +++ b/packages/shared/useInterval/index.ts @@ -1,6 +1,6 @@ import type { Ref } from 'vue-demi' import { ref } from 'vue-demi' -import type { MaybeComputedRef, Pausable } from '../utils' +import type { MaybeRefOrGetter, Pausable } from '../utils' import { useIntervalFn } from '../useIntervalFn' export interface UseIntervalOptions { @@ -36,9 +36,9 @@ export interface UseIntervalControls { * @param interval * @param options */ -export function useInterval(interval?: MaybeComputedRef, options?: UseIntervalOptions): Ref -export function useInterval(interval: MaybeComputedRef, options: UseIntervalOptions): UseIntervalControls & Pausable -export function useInterval(interval: MaybeComputedRef = 1000, options: UseIntervalOptions = {}) { +export function useInterval(interval?: MaybeRefOrGetter, options?: UseIntervalOptions): Ref +export function useInterval(interval: MaybeRefOrGetter, options: UseIntervalOptions): UseIntervalControls & Pausable +export function useInterval(interval: MaybeRefOrGetter = 1000, options: UseIntervalOptions = {}) { const { controls: exposeControls = false, immediate = true, diff --git a/packages/shared/useIntervalFn/index.ts b/packages/shared/useIntervalFn/index.ts index 010c8711f4c..61adf8d1f54 100644 --- a/packages/shared/useIntervalFn/index.ts +++ b/packages/shared/useIntervalFn/index.ts @@ -1,7 +1,7 @@ import { isRef, ref, watch } from 'vue-demi' import { toValue } from '../toValue' import { tryOnScopeDispose } from '../tryOnScopeDispose' -import type { Fn, MaybeComputedRef, Pausable } from '../utils' +import type { Fn, MaybeRefOrGetter, Pausable } from '../utils' import { isClient, isFunction } from '../utils' export interface UseIntervalFnOptions { @@ -27,7 +27,7 @@ export interface UseIntervalFnOptions { * @param interval * @param options */ -export function useIntervalFn(cb: Fn, interval: MaybeComputedRef = 1000, options: UseIntervalFnOptions = {}): Pausable { +export function useIntervalFn(cb: Fn, interval: MaybeRefOrGetter = 1000, options: UseIntervalFnOptions = {}): Pausable { const { immediate = true, immediateCallback = false, diff --git a/packages/shared/useThrottleFn/index.ts b/packages/shared/useThrottleFn/index.ts index 2b997a066bd..5f84df64985 100644 --- a/packages/shared/useThrottleFn/index.ts +++ b/packages/shared/useThrottleFn/index.ts @@ -1,4 +1,4 @@ -import type { FunctionArgs, MaybeComputedRef, PromisifyFn } from '../utils' +import type { FunctionArgs, MaybeRefOrGetter, PromisifyFn } from '../utils' import { createFilterWrapper, throttleFilter } from '../utils' /** @@ -19,7 +19,7 @@ import { createFilterWrapper, throttleFilter } from '../utils' */ export function useThrottleFn( fn: T, - ms: MaybeComputedRef = 200, + ms: MaybeRefOrGetter = 200, trailing = false, leading = true, rejectOnCancel = false, diff --git a/packages/shared/useTimeoutFn/index.ts b/packages/shared/useTimeoutFn/index.ts index fea2ac75914..ea567e3285e 100644 --- a/packages/shared/useTimeoutFn/index.ts +++ b/packages/shared/useTimeoutFn/index.ts @@ -1,5 +1,5 @@ import { readonly, ref } from 'vue-demi' -import type { AnyFn, MaybeComputedRef, Stoppable } from '../utils' +import type { AnyFn, MaybeRefOrGetter, Stoppable } from '../utils' import { toValue } from '../toValue' import { tryOnScopeDispose } from '../tryOnScopeDispose' import { isClient } from '../utils' @@ -22,7 +22,7 @@ export interface UseTimeoutFnOptions { */ export function useTimeoutFn( cb: CallbackFn, - interval: MaybeComputedRef, + interval: MaybeRefOrGetter, options: UseTimeoutFnOptions = {}, ): Stoppable | []> { const { diff --git a/packages/shared/useToNumber/index.ts b/packages/shared/useToNumber/index.ts index 39df08d1774..54b8d2b2438 100644 --- a/packages/shared/useToNumber/index.ts +++ b/packages/shared/useToNumber/index.ts @@ -1,7 +1,7 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' import { toValue } from '../toValue' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' export interface UseToNumberOptions { /** @@ -29,7 +29,7 @@ export interface UseToNumberOptions { * Computed reactive object. */ export function useToNumber( - value: MaybeComputedRef, + value: MaybeRefOrGetter, options: UseToNumberOptions = {}, ): ComputedRef { const { diff --git a/packages/shared/useToString/index.ts b/packages/shared/useToString/index.ts index e1229c4ad9c..0bd58e61b4c 100644 --- a/packages/shared/useToString/index.ts +++ b/packages/shared/useToString/index.ts @@ -1,7 +1,7 @@ import type { ComputedRef } from 'vue-demi' import { computed } from 'vue-demi' import { toValue } from '../toValue' -import type { MaybeComputedRef } from '../utils' +import type { MaybeRefOrGetter } from '../utils' /** * Reactively convert a ref to string. @@ -9,7 +9,7 @@ import type { MaybeComputedRef } from '../utils' * @see https://vueuse.org/useToString */ export function useToString( - value: MaybeComputedRef, + value: MaybeRefOrGetter, ): ComputedRef { return computed(() => `${toValue(value)}`) } diff --git a/packages/shared/useToggle/index.ts b/packages/shared/useToggle/index.ts index 98982df4c10..6971a74b7fa 100644 --- a/packages/shared/useToggle/index.ts +++ b/packages/shared/useToggle/index.ts @@ -1,11 +1,11 @@ import type { Ref } from 'vue-demi' import { isRef, ref } from 'vue-demi' import { toValue } from '../toValue' -import type { MaybeComputedRef, MaybeRef } from '../utils' +import type { MaybeRef, MaybeRefOrGetter } from '../utils' export interface UseToggleOptions { - truthyValue?: MaybeComputedRef - falsyValue?: MaybeComputedRef + truthyValue?: MaybeRefOrGetter + falsyValue?: MaybeRefOrGetter } export function useToggle(initialValue: Ref, options?: UseToggleOptions): (value?: T) => T diff --git a/packages/shared/utils/filters.ts b/packages/shared/utils/filters.ts index 5a41370d7cb..b97985f81f1 100644 --- a/packages/shared/utils/filters.ts +++ b/packages/shared/utils/filters.ts @@ -1,7 +1,7 @@ import { readonly, ref } from 'vue-demi' import { toValue } from '../toValue' import { noop } from './is' -import type { AnyFn, ArgumentsType, MaybeComputedRef, Pausable } from './types' +import type { AnyFn, ArgumentsType, MaybeRefOrGetter, Pausable } from './types' export type FunctionArgs = (...args: Args) => Return @@ -30,7 +30,7 @@ export interface DebounceFilterOptions { * The maximum time allowed to be delayed before it's invoked. * In milliseconds. */ - maxWait?: MaybeComputedRef + maxWait?: MaybeRefOrGetter /** * Whether to reject the last call if it's been cancel. @@ -66,7 +66,7 @@ export const bypassFilter: EventFilter = (invoke) => { * @param ms * @param options */ -export function debounceFilter(ms: MaybeComputedRef, options: DebounceFilterOptions = {}) { +export function debounceFilter(ms: MaybeRefOrGetter, options: DebounceFilterOptions = {}) { let timer: ReturnType | undefined let maxTimer: ReturnType | undefined | null let lastRejector: AnyFn = noop @@ -125,7 +125,7 @@ export function debounceFilter(ms: MaybeComputedRef, options: DebounceFi * @param [leading=true] * @param [rejectOnCancel=false] */ -export function throttleFilter(ms: MaybeComputedRef, trailing = true, leading = true, rejectOnCancel = false) { +export function throttleFilter(ms: MaybeRefOrGetter, trailing = true, leading = true, rejectOnCancel = false) { let lastExec = 0 let timer: ReturnType | undefined let isLeading = true diff --git a/packages/shared/utils/types.ts b/packages/shared/utils/types.ts index 4c1eefd6625..f51905b17ef 100644 --- a/packages/shared/utils/types.ts +++ b/packages/shared/utils/types.ts @@ -1,4 +1,4 @@ -import type { ComputedRef, Ref, WatchOptions, WatchSource } from 'vue-demi' +import type { Ref, WatchOptions, WatchSource } from 'vue-demi' /** * Void function @@ -31,19 +31,10 @@ export type MaybeRef = T | Ref * Maybe it's a ref, or a plain value, or a getter function * * ```ts - * type MaybeComputedRef = (() => T) | T | Ref | ComputedRef + * type MaybeRefOrGetter = (() => T) | T | Ref | ComputedRef * ``` */ -export type MaybeComputedRef = MaybeReadonlyRef | MaybeRef - -/** - * Maybe it's a computed ref, or a getter function - * - * ```ts - * type MaybeReadonlyRef = (() => T) | ComputedRef - * ``` - */ -export type MaybeReadonlyRef = (() => T) | ComputedRef +export type MaybeRefOrGetter = MaybeRef | (() => T) /** * Make all the nested attributes of an object or array to MaybeRef diff --git a/packages/shared/watchAtMost/index.ts b/packages/shared/watchAtMost/index.ts index 20e8d971623..4cf22c1de51 100644 --- a/packages/shared/watchAtMost/index.ts +++ b/packages/shared/watchAtMost/index.ts @@ -1,12 +1,12 @@ import type { Ref, WatchCallback, WatchSource, WatchStopHandle } from 'vue-demi' import { nextTick, ref } from 'vue-demi' import { toValue } from '../toValue' -import type { MapOldSources, MapSources, MaybeComputedRef } from '../utils' +import type { MapOldSources, MapSources, MaybeRefOrGetter } from '../utils' import type { WatchWithFilterOptions } from '../watchWithFilter' import { watchWithFilter } from '../watchWithFilter' export interface WatchAtMostOptions extends WatchWithFilterOptions { - count: MaybeComputedRef + count: MaybeRefOrGetter } export interface WatchAtMostReturn { diff --git a/packages/shared/watchDebounced/index.ts b/packages/shared/watchDebounced/index.ts index abffcaa9e46..d45dc347312 100644 --- a/packages/shared/watchDebounced/index.ts +++ b/packages/shared/watchDebounced/index.ts @@ -1,10 +1,10 @@ import type { WatchCallback, WatchOptions, WatchSource, WatchStopHandle } from 'vue-demi' -import type { DebounceFilterOptions, MapOldSources, MapSources, MaybeComputedRef } from '../utils' +import type { DebounceFilterOptions, MapOldSources, MapSources, MaybeRefOrGetter } from '../utils' import { debounceFilter } from '../utils' import { watchWithFilter } from '../watchWithFilter' export interface WatchDebouncedOptions extends WatchOptions, DebounceFilterOptions { - debounce?: MaybeComputedRef + debounce?: MaybeRefOrGetter } // overloads diff --git a/packages/shared/watchThrottled/index.ts b/packages/shared/watchThrottled/index.ts index ad259a4e2f7..59b7e9d35b4 100644 --- a/packages/shared/watchThrottled/index.ts +++ b/packages/shared/watchThrottled/index.ts @@ -1,10 +1,10 @@ import type { WatchCallback, WatchOptions, WatchSource, WatchStopHandle } from 'vue-demi' -import type { MapOldSources, MapSources, MaybeComputedRef } from '../utils' +import type { MapOldSources, MapSources, MaybeRefOrGetter } from '../utils' import { throttleFilter } from '../utils' import { watchWithFilter } from '../watchWithFilter' export interface WatchThrottledOptions extends WatchOptions { - throttle?: MaybeComputedRef + throttle?: MaybeRefOrGetter trailing?: boolean leading?: boolean }