diff --git a/libs/horizon/src/dom/DOMPropertiesHandler/DOMPropertiesHandler.ts b/libs/horizon/src/dom/DOMPropertiesHandler/DOMPropertiesHandler.ts index 496d0c2c..9b272aaf 100644 --- a/libs/horizon/src/dom/DOMPropertiesHandler/DOMPropertiesHandler.ts +++ b/libs/horizon/src/dom/DOMPropertiesHandler/DOMPropertiesHandler.ts @@ -8,28 +8,6 @@ import { } from '../../event/EventBinding'; import { isEventProp, isNativeElement } from '../validators/ValidateProps'; -function updateOneProp(dom, propName, isNativeTag, propVal?, isInit?: boolean) { - if (propName === 'style') { - setStyles(dom, propVal); - } else if (isEventProp(propName)) { - // 事件监听属性处理 - if (!allDelegatedHorizonEvents.has(propName)) { - listenNonDelegatedEvent(propName, dom, propVal); - } - } else if (propName === 'children') { // 只处理纯文本子节点,其他children在VNode树中处理 - const type = typeof propVal; - if (type === 'string' || type === 'number') { - dom.textContent = propVal; - } - } else if (propName === 'dangerouslySetInnerHTML') { - dom.innerHTML = propVal.__html; - } else { - if (!isInit || (isInit && propVal != null)) { - updateCommonProp(dom, propName, propVal, isNativeTag); - } - } -} - // 初始化DOM属性 export function setDomProps( tagName: string, @@ -45,7 +23,25 @@ export function setDomProps( propName = keysOfProps[i]; propVal = props[propName]; - updateOneProp(dom, propName, isNativeTag, propVal, true); + if (propName === 'style') { + setStyles(dom, propVal); + } else if (isEventProp(propName)) { + // 事件监听属性处理 + if (!allDelegatedHorizonEvents.has(propName)) { + listenNonDelegatedEvent(propName, dom, propVal); + } + } else if (propName === 'children') { // 只处理纯文本子节点,其他children在VNode树中处理 + const type = typeof propVal; + if (type === 'string' || type === 'number') { + dom.textContent = propVal; + } + } else if (propName === 'dangerouslySetInnerHTML') { + dom.innerHTML = propVal.__html; + } else { + if (propVal != null) { + updateCommonProp(dom, propName, propVal, isNativeTag); + } + } } } @@ -56,7 +52,23 @@ export function updateDomProps( isNativeTag: boolean, ): void { for(const [propName, propVal] of changeList) { - updateOneProp(dom, propName, isNativeTag, propVal); + if (propName === 'style') { + setStyles(dom, propVal); + } else if (isEventProp(propName)) { + // 事件监听属性处理 + if (!allDelegatedHorizonEvents.has(propName)) { + listenNonDelegatedEvent(propName, dom, propVal); + } + } else if (propName === 'children') { // 只处理纯文本子节点,其他children在VNode树中处理 + const type = typeof propVal; + if (type === 'string' || type === 'number') { + dom.textContent = propVal; + } + } else if (propName === 'dangerouslySetInnerHTML') { + dom.innerHTML = propVal.__html; + } else { + updateCommonProp(dom, propName, propVal, isNativeTag); + } } }