Skip to content

Commit

Permalink
chore: futher optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Nov 22, 2024
1 parent 217748e commit 26cfbb1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/compiler-vapor/src/generators/prop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
genMulti,
} from './utils'
import {
attributeCache,
isHTMLGlobalAttr,
isHTMLTag,
isMathMLGlobalAttr,
Expand All @@ -44,6 +45,8 @@ export function genSetProp(
} = oper

const keyName = key.content
const tagName = tag.toUpperCase()
const attrCacheKey = `${tagName}_${keyName}`

let helperName: VaporHelper
let omitKey = false
Expand All @@ -55,7 +58,10 @@ export function genSetProp(
omitKey = true
} else if (modifier) {
helperName = modifier === '.' ? 'setDOMProp' : 'setAttr'
} else if (shouldSetAsAttr(tag.toUpperCase(), keyName)) {
} else if (
attributeCache[attrCacheKey] ||
(attributeCache[attrCacheKey] = shouldSetAsAttr(tag.toUpperCase(), keyName))
) {
helperName = 'setAttr'
} else if (
(isHTMLTag(tag) && isHTMLGlobalAttr(keyName)) ||
Expand Down
7 changes: 6 additions & 1 deletion packages/runtime-vapor/src/dom/prop.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
attributeCache,
includeBooleanAttr,
isArray,
isFunction,
Expand Down Expand Up @@ -243,7 +244,11 @@ function shouldSetAsProp(
return false
}

if (shouldSetAsAttr(el.tagName, key)) {
const attrCacheKey = `${el.tagName}_${key}`
if (
attributeCache[attrCacheKey] ||
(attributeCache[attrCacheKey] = shouldSetAsAttr(el.tagName, key))
) {
return false
}

Expand Down
5 changes: 5 additions & 0 deletions packages/shared/src/domAttrConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ export function isRenderableAttrValue(value: unknown): boolean {
return type === 'string' || type === 'number' || type === 'boolean'
}

/**
* cache seen attributes which must be set as attribute
*/
export const attributeCache: Record<string, boolean> = Object.create(null)

/*
* The following attributes must be set as attribute
*/
Expand Down

0 comments on commit 26cfbb1

Please sign in to comment.