Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 2b3962f

Browse files
committed
refactor: optimize attrs
1 parent 83e4102 commit 2b3962f

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

packages/runtime-vapor/src/componentAttrs.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ export function patchAttrs(instance: ComponentInternalInstance) {
77
const options = instance.propsOptions[0]
88

99
const keys = new Set<string>()
10-
for (const props of Array.from(instance.rawProps).reverse()) {
11-
if (isFunction(props)) {
12-
const resolved = props()
13-
for (const rawKey in resolved) {
14-
registerAttr(rawKey, () => resolved[rawKey])
15-
}
16-
} else {
17-
for (const rawKey in props) {
18-
registerAttr(rawKey, props[rawKey])
10+
if (instance.rawProps.length)
11+
for (const props of Array.from(instance.rawProps).reverse()) {
12+
if (isFunction(props)) {
13+
const resolved = props()
14+
for (const rawKey in resolved) {
15+
registerAttr(rawKey, () => resolved[rawKey])
16+
}
17+
} else {
18+
for (const rawKey in props) {
19+
registerAttr(rawKey, props[rawKey])
20+
}
1921
}
2022
}
21-
}
2223

2324
for (const key in attrs) {
2425
if (!keys.has(key)) {

packages/runtime-vapor/src/componentProps.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ export function initProps(
9191

9292
const [options] = instance.propsOptions
9393

94+
const hasDynamicProps = rawProps.some(isFunction)
9495
if (options) {
95-
const hasDynamicProps = rawProps.some(isFunction)
9696
if (hasDynamicProps) {
9797
for (const key in options) {
9898
const getter = () =>
@@ -121,9 +121,13 @@ export function initProps(
121121
validateProps(rawProps, props, options || {})
122122
}
123123

124-
baseWatch(() => patchAttrs(instance), undefined, {
125-
scheduler: createVaporPreScheduler(instance),
126-
})
124+
if (hasDynamicProps) {
125+
baseWatch(() => patchAttrs(instance), undefined, {
126+
scheduler: createVaporPreScheduler(instance),
127+
})
128+
} else {
129+
patchAttrs(instance)
130+
}
127131

128132
if (isStateful) {
129133
instance.props = props

0 commit comments

Comments
 (0)