Replace useAutoRef with Vue's toRef (#1332)

Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
Sasha Sorokin
2024-07-31 21:44:48 +02:00
committed by GitHub
parent 1e0d7c7e28
commit 4fcd518b0a
2 changed files with 7 additions and 19 deletions

View File

@@ -1,13 +0,0 @@
export type AutoRef<T> = [T] extends [(...args: any[]) => any]
? Ref<T> | (() => T)
: T | Ref<T> | (() => T);
/**
* Accepts a value directly, a ref with the value or a getter function and returns a Vue ref.
* @param value The value to use.
* @returns Either the original or newly created ref.
*/
export function useAutoRef<T>(value: AutoRef<T>): Ref<T> {
if (typeof value === "function") return computed(() => value());
return isRef(value) ? value : ref(value as any);
}

View File

@@ -1,5 +1,3 @@
import { useAutoRef, type AutoRef } from "./auto-ref.ts";
const safeTags = new Map<string, string>();
function safeTagFor(locale: string) {
@@ -81,11 +79,14 @@ export function createDisplayNames(
}
export function useDisplayNames(
locale: AutoRef<string>,
options?: AutoRef<Intl.DisplayNamesOptions | undefined>,
locale: string | (() => string) | Ref<string>,
options?:
| (Intl.DisplayNamesOptions | undefined)
| (() => Intl.DisplayNamesOptions | undefined)
| Ref<Intl.DisplayNamesOptions | undefined>,
) {
const $locale = useAutoRef(locale);
const $options = useAutoRef(options);
const $locale = toRef(locale);
const $options = toRef(options);
return computed(() => createDisplayNames($locale.value, $options.value));
}