Match-id-342c2da56a252520c7e3a8208993538ef34cfb23
This commit is contained in:
parent
b7183f1082
commit
56dd409cbc
|
@ -110,7 +110,7 @@ export function getPropChangeList(
|
||||||
type: string,
|
type: string,
|
||||||
lastRawProps: Props,
|
lastRawProps: Props,
|
||||||
nextRawProps: Props,
|
nextRawProps: Props,
|
||||||
): Map<string, any> {
|
): Object {
|
||||||
// 校验两个对象的不同
|
// 校验两个对象的不同
|
||||||
validateProps(type, nextRawProps);
|
validateProps(type, nextRawProps);
|
||||||
|
|
||||||
|
@ -118,8 +118,7 @@ export function getPropChangeList(
|
||||||
const oldProps: Object = getPropsWithoutValue(type, dom, lastRawProps);
|
const oldProps: Object = getPropsWithoutValue(type, dom, lastRawProps);
|
||||||
const newProps: Object = getPropsWithoutValue(type, dom, nextRawProps);
|
const newProps: Object = getPropsWithoutValue(type, dom, nextRawProps);
|
||||||
|
|
||||||
const changeList = compareProps(oldProps, newProps);
|
return compareProps(oldProps, newProps);
|
||||||
return changeList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isTextChild(type: string, props: Props): boolean {
|
export function isTextChild(type: string, props: Props): boolean {
|
||||||
|
|
|
@ -48,10 +48,16 @@ export function setDomProps(
|
||||||
// 更新 DOM 属性
|
// 更新 DOM 属性
|
||||||
export function updateDomProps(
|
export function updateDomProps(
|
||||||
dom: Element,
|
dom: Element,
|
||||||
changeList: Map<string, any>,
|
changeList: Object,
|
||||||
isNativeTag: boolean,
|
isNativeTag: boolean,
|
||||||
): void {
|
): 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') {
|
if (propName === 'style') {
|
||||||
setStyles(dom, propVal);
|
setStyles(dom, propVal);
|
||||||
} else if (isEventProp(propName)) {
|
} else if (isEventProp(propName)) {
|
||||||
|
@ -76,9 +82,9 @@ export function updateDomProps(
|
||||||
export function compareProps(
|
export function compareProps(
|
||||||
oldProps: Object,
|
oldProps: Object,
|
||||||
newProps: Object,
|
newProps: Object,
|
||||||
): Map<string, any> {
|
): Object {
|
||||||
let updatesForStyle = {};
|
let updatesForStyle = {};
|
||||||
const toUpdateProps = new Map();
|
const toUpdateProps = {};
|
||||||
const keysOfOldProps = Object.keys(oldProps);
|
const keysOfOldProps = Object.keys(oldProps);
|
||||||
const keysOfNewProps = Object.keys(newProps);
|
const keysOfNewProps = Object.keys(newProps);
|
||||||
|
|
||||||
|
@ -110,11 +116,11 @@ export function compareProps(
|
||||||
continue;
|
continue;
|
||||||
} else if (isEventProp(propName)) {
|
} else if (isEventProp(propName)) {
|
||||||
if (!allDelegatedHorizonEvents.has(propName)) {
|
if (!allDelegatedHorizonEvents.has(propName)) {
|
||||||
toUpdateProps.set(propName, null);
|
toUpdateProps[propName] = null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 其它属性都要加入到删除队列里面,等待删除
|
// 其它属性都要加入到删除队列里面,等待删除
|
||||||
toUpdateProps.set(propName, null);
|
toUpdateProps[propName] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +162,7 @@ export function compareProps(
|
||||||
}
|
}
|
||||||
} else { // 之前未设置 style 属性或者设置了空值
|
} else { // 之前未设置 style 属性或者设置了空值
|
||||||
if (Object.keys(updatesForStyle).length === 0) {
|
if (Object.keys(updatesForStyle).length === 0) {
|
||||||
toUpdateProps.set(propName, null);
|
toUpdateProps[propName] = null;
|
||||||
}
|
}
|
||||||
updatesForStyle = newPropValue;
|
updatesForStyle = newPropValue;
|
||||||
}
|
}
|
||||||
|
@ -165,25 +171,25 @@ export function compareProps(
|
||||||
oldHTML = oldPropValue ? oldPropValue.__html : undefined;
|
oldHTML = oldPropValue ? oldPropValue.__html : undefined;
|
||||||
if (newHTML != null) {
|
if (newHTML != null) {
|
||||||
if (oldHTML !== newHTML) {
|
if (oldHTML !== newHTML) {
|
||||||
toUpdateProps.set(propName, newPropValue);
|
toUpdateProps[propName] = newPropValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (propName === 'children') {
|
} else if (propName === 'children') {
|
||||||
if (typeof newPropValue === 'string' || typeof newPropValue === 'number') {
|
if (typeof newPropValue === 'string' || typeof newPropValue === 'number') {
|
||||||
toUpdateProps.set(propName, String(newPropValue));
|
toUpdateProps[propName] = String(newPropValue);
|
||||||
}
|
}
|
||||||
} else if (isEventProp(propName)) {
|
} else if (isEventProp(propName)) {
|
||||||
if (!allDelegatedHorizonEvents.has(propName)) {
|
if (!allDelegatedHorizonEvents.has(propName)) {
|
||||||
toUpdateProps.set(propName, newPropValue);
|
toUpdateProps[propName] = newPropValue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
toUpdateProps.set(propName, newPropValue);
|
toUpdateProps[propName] = newPropValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理style
|
// 处理style
|
||||||
if (Object.keys(updatesForStyle).length > 0) {
|
if (Object.keys(updatesForStyle).length > 0) {
|
||||||
toUpdateProps.set('style', updatesForStyle);
|
toUpdateProps['style'] = updatesForStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
return toUpdateProps;
|
return toUpdateProps;
|
||||||
|
|
|
@ -45,7 +45,7 @@ function updateDom(
|
||||||
FlagUtils.markUpdate(processing);
|
FlagUtils.markUpdate(processing);
|
||||||
} else {
|
} else {
|
||||||
// 其它的类型,数据有变化才标记更新
|
// 其它的类型,数据有变化才标记更新
|
||||||
if (changeList.size) {
|
if (Object.keys(changeList).length) {
|
||||||
FlagUtils.markUpdate(processing);
|
FlagUtils.markUpdate(processing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue