eagerComputed.js 254 B

12345678910
  1. import { watchEffect, shallowRef } from 'vue';
  2. export default function eagerComputed(fn) {
  3. const result = shallowRef();
  4. watchEffect(() => {
  5. result.value = fn();
  6. }, {
  7. flush: 'sync' // needed so updates are immediate.
  8. });
  9. return result;
  10. }