cache.ts 379 B

12345678910111213141516171819202122232425262728
  1. import { reactive, watch } from "vue";
  2. import { isDark } from "../theme";
  3. type CacheData = {
  4. key: number;
  5. };
  6. type UseCache = {
  7. cache: CacheData;
  8. };
  9. export const useCache = (source: () => any[]): UseCache => {
  10. const cache = reactive<CacheData>({
  11. key: 0
  12. });
  13. watch(source, () => {
  14. cache.key++;
  15. });
  16. watch(isDark, () => {
  17. cache.key++;
  18. });
  19. return {
  20. cache
  21. };
  22. };