Match-id-cd373c95d0b3324947f005897eb475632af01f79

This commit is contained in:
* 2022-02-23 16:15:21 +08:00 committed by *
parent 0492221e89
commit a36f7f9260
2 changed files with 9 additions and 43 deletions

View File

@ -19,7 +19,7 @@ import {
} from './valueHandler';
import {
compareProps,
setDomProps, updateDomProps
setDomProps,
} from './DOMPropertiesHandler/DOMPropertiesHandler';
import { isNativeElement, validateProps } from './validators/ValidateProps';
import { watchValueChange } from './valueHandler/ValueChangeHandler';
@ -91,7 +91,8 @@ export function initDomProps(dom: Element, tagName: string, rawProps: Props): bo
const props: Object = getPropsWithoutValue(tagName, dom, rawProps);
// 初始化DOM属性不包括valuedefaultValue
setDomProps(tagName, dom, props);
const isNativeTag = isNativeElement(tagName, props);
setDomProps(dom, props, isNativeTag, true);
if (tagName === 'input' || tagName === 'textarea') {
// 增加监听value和checked的set、get方法
@ -167,7 +168,7 @@ export function submitDomUpdate(tag: string, vNode: VNode) {
updateCommonProp(element, 'checked', newProps.checked, true);
}
const isNativeTag = isNativeElement(type, newProps);
updateDomProps(element, changeList, isNativeTag);
setDomProps(element, changeList, isNativeTag, false);
updateValue(type, element, newProps);
}
}

View File

@ -6,15 +6,15 @@ import { setStyles } from './StyleHandler';
import {
listenNonDelegatedEvent
} from '../../event/EventBinding';
import { isEventProp, isNativeElement } from '../validators/ValidateProps';
import { isEventProp } from '../validators/ValidateProps';
// 初始化DOM属性
// 初始化DOM属性和更新 DOM 属性
export function setDomProps(
tagName: string,
dom: Element,
props: Object,
isNativeTag: boolean,
isInit: boolean,
): void {
const isNativeTag = isNativeElement(tagName, props);
const keysOfProps = Object.keys(props);
let propName;
let propVal;
@ -37,42 +37,7 @@ export function setDomProps(
}
} else if (propName === 'dangerouslySetInnerHTML') {
dom.innerHTML = propVal.__html;
} else {
if (propVal != null) {
updateCommonProp(dom, propName, propVal, isNativeTag);
}
}
}
}
// 更新 DOM 属性
export function updateDomProps(
dom: Element,
changeList: Object,
isNativeTag: boolean,
): void {
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)) {
// 事件监听属性处理
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 {
} else if (!isInit || (isInit && propVal != null)) {
updateCommonProp(dom, propName, propVal, isNativeTag);
}
}