perf(additional-components): inject slots to avoid performance drop

This commit is contained in:
braks
2022-11-08 20:46:38 +01:00
committed by Braks
parent a27ccc4683
commit 0c0bfe48ad
3 changed files with 14 additions and 31 deletions
@@ -1,12 +1,14 @@
import type { CSSProperties } from 'vue'
import type { CSSProperties, Slots } from 'vue'
import type { MiniMapNodeProps } from './types'
import { MiniMapSlots } from './types'
export default defineComponent({
name: 'MiniMapNode',
props: ['id', 'position', 'dimensions', 'strokeWidth', 'strokeColor', 'borderRadius', 'color', 'shapeRendering'],
props: ['id', 'position', 'dimensions', 'strokeWidth', 'strokeColor', 'borderRadius', 'color', 'shapeRendering', 'type'],
emits: ['click', 'dblclick', 'mouseenter', 'mousemove', 'mouseleave'],
setup(props: MiniMapNodeProps, { attrs, emit, slots }) {
setup(props: MiniMapNodeProps, { attrs, emit }) {
const style = (attrs.style ?? {}) as CSSProperties
const miniMapSlots: Slots = inject(MiniMapSlots)!
return () => [
h('rect', {
@@ -29,7 +31,7 @@ export default defineComponent({
onMousemove: (e: MouseEvent) => emit('mousemove', e),
onMouseleave: (e: MouseEvent) => emit('mouseleave', e),
}),
slots?.default?.(),
miniMapSlots[props.type] && miniMapSlots[props.type]!(props),
]
},
})