You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/_util/eagerComputed.ts

17 lines
431 B

import { watchEffect, shallowRef } from 'vue';
import type { ComputedRef } from 'vue';
export declare type ComputedGetter<T> = (...args: any[]) => T;
export default function eagerComputed<T>(fn: ComputedGetter<T>) {
const result = shallowRef<T>();
watchEffect(
() => {
result.value = fn();
},
{
flush: 'sync', // needed so updates are immediate.
},
);
return result as any as ComputedRef<T>;
}