useMemo.js 466 B

1234567891011121314151617181920
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = useMemo;
  6. var _vue = require("vue");
  7. function useMemo(getValue, condition, shouldUpdate) {
  8. const cacheRef = (0, _vue.ref)(getValue());
  9. (0, _vue.watch)(condition, (next, pre) => {
  10. if (shouldUpdate) {
  11. if (shouldUpdate(next, pre)) {
  12. cacheRef.value = getValue();
  13. }
  14. } else {
  15. cacheRef.value = getValue();
  16. }
  17. });
  18. return cacheRef;
  19. }