refactor: cssinjs

pull/6213/head
tangjinzhou 2023-01-25 11:28:53 +08:00
parent c0d7d041b4
commit b2841a27ae
4 changed files with 19 additions and 64 deletions

View File

@ -15,8 +15,8 @@ export default function useClientCache<CacheType>(
const fullPath = computed(() => [prefix, ...keyPath.value]); const fullPath = computed(() => [prefix, ...keyPath.value]);
const fullPathStr = eagerComputed(() => fullPath.value.join('_')); const fullPathStr = eagerComputed(() => fullPath.value.join('_'));
const HMRUpdate = useHMR(); const HMRUpdate = useHMR();
const clearCache = () => { const clearCache = (paths: typeof fullPath.value) => {
styleContext.cache.update(fullPath.value, prevCache => { styleContext.cache.update(paths, prevCache => {
const [times = 0, cache] = prevCache || []; const [times = 0, cache] = prevCache || [];
const nextCount = times - 1; const nextCount = times - 1;
@ -28,11 +28,16 @@ export default function useClientCache<CacheType>(
return [times - 1, cache]; return [times - 1, cache];
}); });
}; };
watch(
() => fullPath.value.slice(),
(_, oldValue) => {
clearCache(oldValue);
},
);
// Create cache // Create cache
watch( watch(
fullPathStr, fullPathStr,
() => { () => {
clearCache();
styleContext.cache.update(fullPath.value, prevCache => { styleContext.cache.update(fullPath.value, prevCache => {
const [times = 0, cache] = prevCache || []; const [times = 0, cache] = prevCache || [];
@ -50,9 +55,8 @@ export default function useClientCache<CacheType>(
}, },
{ immediate: true }, { immediate: true },
); );
onBeforeUnmount(() => { onBeforeUnmount(() => {
clearCache(); clearCache(fullPath.value);
}); });
const val = computed(() => styleContext.cache.get(fullPath.value)![1]); const val = computed(() => styleContext.cache.get(fullPath.value)![1]);
return val; return val;

View File

@ -15,10 +15,12 @@ export default process.env.NODE_ENV === 'production' ? useProdHMR : useDevHMR;
// We have to hack handler to force mark as HRM // We have to hack handler to force mark as HRM
if ( if (
process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'production' &&
typeof module !== 'undefined' && ((typeof module !== 'undefined' &&
module && module &&
// @ts-ignore // @ts-ignore
module.hot module.hot) ||
// @ts-ignore
import.meta.hot)
) { ) {
const win = window as any; const win = window as any;
@ -34,12 +36,6 @@ if (
}; };
// @ts-ignore // @ts-ignore
} else if (import.meta.hot) { } else if (import.meta.hot) {
// @ts-ignore viteHMR = true;
import.meta.hot.accept(() => {
viteHMR = true;
setTimeout(() => {
viteHMR = false;
}, 0);
});
} }
} }

View File

@ -1,8 +1,8 @@
import canUseDom from '../../_util/canUseDom'; import canUseDom from '../../_util/canUseDom';
import contains from './contains'; import contains from './contains';
const APPEND_ORDER = 'data-rc-order'; const APPEND_ORDER = 'data-vc-order';
const MARK_KEY = `rc-util-key`; const MARK_KEY = `vc-util-key`;
const containerCache = new Map<ContainerType, Node & ParentNode>(); const containerCache = new Map<ContainerType, Node & ParentNode>();

View File

@ -1,48 +1,3 @@
<template> <template>
<div> <a-alert message="Success Text" prefix-cls="tes" type="success" />
<a-menu
v-model:selected-keys="selectedKeys"
:open-keys="openKeys"
style="width: 256px"
mode="inline"
>
<a-sub-menu key="sub1">
<template #icon>
<MailOutlined />
</template>
<template #title>Navigation One</template>
<a-menu-item key="3">Option 3</a-menu-item>
<a-menu-item key="4">Option 4</a-menu-item>
</a-sub-menu>
</a-menu>
<a-button @click="open"></a-button>
</div>
</template> </template>
<script>
import { defineComponent, ref, watchEffect } from 'vue';
import { MailOutlined } from '@ant-design/icons-vue';
export default defineComponent({
components: {
MailOutlined,
},
setup() {
const selectedKeys = ref(['1']);
const openKeys = ref([]);
const open = () => {
openKeys.value.push('sub1');
// openKeys.value = [...openKeys.value, 'sub1'];
};
const test = ref([1]);
watchEffect(() => {
console.log(111, test.value);
});
window.openKeys = openKeys;
window.test = test;
return {
selectedKeys,
openKeys,
open,
};
},
});
</script>