From 56dd409cbc7d92d7ca8069753b0e89809ca955e1 Mon Sep 17 00:00:00 2001 From: * <8> Date: Wed, 23 Feb 2022 15:40:07 +0800 Subject: [PATCH] Match-id-342c2da56a252520c7e3a8208993538ef34cfb23 --- libs/horizon/src/dom/DOMOperator.ts | 5 ++-- .../DOMPropertiesHandler.ts | 30 +++++++++++-------- .../src/renderer/render/DomComponent.ts | 2 +- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/libs/horizon/src/dom/DOMOperator.ts b/libs/horizon/src/dom/DOMOperator.ts index bb061fa7..894ccd96 100644 --- a/libs/horizon/src/dom/DOMOperator.ts +++ b/libs/horizon/src/dom/DOMOperator.ts @@ -110,7 +110,7 @@ export function getPropChangeList( type: string, lastRawProps: Props, nextRawProps: Props, -): Map { +): Object { // 校验两个对象的不同 validateProps(type, nextRawProps); @@ -118,8 +118,7 @@ export function getPropChangeList( const oldProps: Object = getPropsWithoutValue(type, dom, lastRawProps); const newProps: Object = getPropsWithoutValue(type, dom, nextRawProps); - const changeList = compareProps(oldProps, newProps); - return changeList; + return compareProps(oldProps, newProps); } export function isTextChild(type: string, props: Props): boolean { diff --git a/libs/horizon/src/dom/DOMPropertiesHandler/DOMPropertiesHandler.ts b/libs/horizon/src/dom/DOMPropertiesHandler/DOMPropertiesHandler.ts index 9b272aaf..e35e2b2a 100644 --- a/libs/horizon/src/dom/DOMPropertiesHandler/DOMPropertiesHandler.ts +++ b/libs/horizon/src/dom/DOMPropertiesHandler/DOMPropertiesHandler.ts @@ -48,10 +48,16 @@ export function setDomProps( // 更新 DOM 属性 export function updateDomProps( dom: Element, - changeList: Map, + changeList: Object, isNativeTag: boolean, ): void { - for(const [propName, propVal] of changeList) { + const keysOfProps = Object.keys(changeList); + let propName; + let propVal; + const keyLength = keysOfProps.length; + for(let i = 0; i < keyLength; i++) { + propName = keysOfProps[i]; + propVal = changeList[propName]; if (propName === 'style') { setStyles(dom, propVal); } else if (isEventProp(propName)) { @@ -76,9 +82,9 @@ export function updateDomProps( export function compareProps( oldProps: Object, newProps: Object, -): Map { +): Object { let updatesForStyle = {}; - const toUpdateProps = new Map(); + const toUpdateProps = {}; const keysOfOldProps = Object.keys(oldProps); const keysOfNewProps = Object.keys(newProps); @@ -110,11 +116,11 @@ export function compareProps( continue; } else if (isEventProp(propName)) { if (!allDelegatedHorizonEvents.has(propName)) { - toUpdateProps.set(propName, null); + toUpdateProps[propName] = null; } } else { // 其它属性都要加入到删除队列里面,等待删除 - toUpdateProps.set(propName, null); + toUpdateProps[propName] = null; } } @@ -156,7 +162,7 @@ export function compareProps( } } else { // 之前未设置 style 属性或者设置了空值 if (Object.keys(updatesForStyle).length === 0) { - toUpdateProps.set(propName, null); + toUpdateProps[propName] = null; } updatesForStyle = newPropValue; } @@ -165,25 +171,25 @@ export function compareProps( oldHTML = oldPropValue ? oldPropValue.__html : undefined; if (newHTML != null) { if (oldHTML !== newHTML) { - toUpdateProps.set(propName, newPropValue); + toUpdateProps[propName] = newPropValue; } } } else if (propName === 'children') { if (typeof newPropValue === 'string' || typeof newPropValue === 'number') { - toUpdateProps.set(propName, String(newPropValue)); + toUpdateProps[propName] = String(newPropValue); } } else if (isEventProp(propName)) { if (!allDelegatedHorizonEvents.has(propName)) { - toUpdateProps.set(propName, newPropValue); + toUpdateProps[propName] = newPropValue; } } else { - toUpdateProps.set(propName, newPropValue); + toUpdateProps[propName] = newPropValue; } } // 处理style if (Object.keys(updatesForStyle).length > 0) { - toUpdateProps.set('style', updatesForStyle); + toUpdateProps['style'] = updatesForStyle; } return toUpdateProps; diff --git a/libs/horizon/src/renderer/render/DomComponent.ts b/libs/horizon/src/renderer/render/DomComponent.ts index 8baf71e4..7d5a0503 100644 --- a/libs/horizon/src/renderer/render/DomComponent.ts +++ b/libs/horizon/src/renderer/render/DomComponent.ts @@ -45,7 +45,7 @@ function updateDom( FlagUtils.markUpdate(processing); } else { // 其它的类型,数据有变化才标记更新 - if (changeList.size) { + if (Object.keys(changeList).length) { FlagUtils.markUpdate(processing); } }