mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-05 05:29:01 +08:00
17 lines
431 B
TypeScript
17 lines
431 B
TypeScript
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>;
|
|
}
|