From 357151139444f7615378aaefa0ad85ef69dab35c Mon Sep 17 00:00:00 2001 From: vben Date: Sat, 6 Jul 2024 21:53:02 +0800 Subject: [PATCH] perf: reduce the number of icon component instances --- packages/@core/shared/iconify/src/create-icon.ts | 9 +++++++++ packages/@core/shared/iconify/src/factory.ts | 14 -------------- packages/@core/shared/iconify/src/index.ts | 2 +- packages/@core/shared/iconify/src/material.ts | 2 +- packages/@core/shared/iconify/src/mdi.ts | 2 +- .../widgets/src/preferences/blocks/input-item.vue | 2 +- .../src/preferences/blocks/number-field-item.vue | 2 +- .../widgets/src/preferences/blocks/select-item.vue | 2 +- packages/locales/src/langs/en-US.yaml | 4 ++-- packages/locales/src/langs/zh-CN.yaml | 4 ++-- 10 files changed, 19 insertions(+), 24 deletions(-) create mode 100644 packages/@core/shared/iconify/src/create-icon.ts delete mode 100644 packages/@core/shared/iconify/src/factory.ts diff --git a/packages/@core/shared/iconify/src/create-icon.ts b/packages/@core/shared/iconify/src/create-icon.ts new file mode 100644 index 00000000..05d4c986 --- /dev/null +++ b/packages/@core/shared/iconify/src/create-icon.ts @@ -0,0 +1,9 @@ +import { h } from 'vue'; + +import { Icon } from '@iconify/vue'; + +function createIcon(icon: string) { + return h(Icon, { icon }); +} + +export { createIcon }; diff --git a/packages/@core/shared/iconify/src/factory.ts b/packages/@core/shared/iconify/src/factory.ts deleted file mode 100644 index 2b34d6f7..00000000 --- a/packages/@core/shared/iconify/src/factory.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { defineComponent, h } from 'vue'; - -import { Icon } from '@iconify/vue'; - -function createIcon(name: string) { - return defineComponent({ - name: `SvgIcon-${name}`, - setup(props, { attrs }) { - return () => h(Icon, { icon: name, ...props, ...attrs }); - }, - }); -} - -export { createIcon }; diff --git a/packages/@core/shared/iconify/src/index.ts b/packages/@core/shared/iconify/src/index.ts index e343d5c8..ccfa63b7 100644 --- a/packages/@core/shared/iconify/src/index.ts +++ b/packages/@core/shared/iconify/src/index.ts @@ -1,4 +1,4 @@ -export * from './factory'; +export * from './create-icon'; export * from './material'; export * from './mdi'; diff --git a/packages/@core/shared/iconify/src/material.ts b/packages/@core/shared/iconify/src/material.ts index d36cf69c..db5a0e0e 100644 --- a/packages/@core/shared/iconify/src/material.ts +++ b/packages/@core/shared/iconify/src/material.ts @@ -1,4 +1,4 @@ -import { createIcon } from './factory'; +import { createIcon } from './create-icon'; export const IconDefault = createIcon('ic:round-auto-awesome'); diff --git a/packages/@core/shared/iconify/src/mdi.ts b/packages/@core/shared/iconify/src/mdi.ts index 79034178..1bcda36d 100644 --- a/packages/@core/shared/iconify/src/mdi.ts +++ b/packages/@core/shared/iconify/src/mdi.ts @@ -1,4 +1,4 @@ -import { createIcon } from './factory'; +import { createIcon } from './create-icon'; export const MdiKeyboardEsc = createIcon('mdi:keyboard-esc'); diff --git a/packages/business/widgets/src/preferences/blocks/input-item.vue b/packages/business/widgets/src/preferences/blocks/input-item.vue index 4c68c643..5f21943f 100644 --- a/packages/business/widgets/src/preferences/blocks/input-item.vue +++ b/packages/business/widgets/src/preferences/blocks/input-item.vue @@ -46,6 +46,6 @@ const slots = useSlots(); - + diff --git a/packages/business/widgets/src/preferences/blocks/number-field-item.vue b/packages/business/widgets/src/preferences/blocks/number-field-item.vue index bc9cfbd7..9529a31e 100644 --- a/packages/business/widgets/src/preferences/blocks/number-field-item.vue +++ b/packages/business/widgets/src/preferences/blocks/number-field-item.vue @@ -54,7 +54,7 @@ const slots = useSlots(); - + diff --git a/packages/business/widgets/src/preferences/blocks/select-item.vue b/packages/business/widgets/src/preferences/blocks/select-item.vue index 0920d787..a946dd7d 100644 --- a/packages/business/widgets/src/preferences/blocks/select-item.vue +++ b/packages/business/widgets/src/preferences/blocks/select-item.vue @@ -54,7 +54,7 @@ const slots = useSlots();