@cran/lib.vue.ref
Version:
Vue Reactivity Extensions
26 lines (25 loc) • 861 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.eagerComputed = void 0;
const vue_1 = require("vue");
/**
* Use computed() when you have a complex
* calculation going on, which can actually profit
* from caching and lazy evaluation and should only
* be (re-)calculated if really necessary.
*
* Use eagerComputed() when you have a simple
* operation, with a rarely changing return value –
* often a boolean.
* @since 0.0.1
* @category Utility
* @see https://dev.to/linusborg/vue-when-a-computed-property-can-be-the-wrong-tool-195j
*/
function eagerComputed(factory) {
const result = (0, vue_1.shallowRef)();
(0, vue_1.watchEffect)(function onEffect() {
result.value = factory();
}, { flush: "sync", });
return (0, vue_1.shallowReadonly)(result);
}
exports.eagerComputed = eagerComputed;