Match-id-cd373c95d0b3324947f005897eb475632af01f79
This commit is contained in:
parent
0492221e89
commit
a36f7f9260
|
@ -19,7 +19,7 @@ import {
|
||||||
} from './valueHandler';
|
} from './valueHandler';
|
||||||
import {
|
import {
|
||||||
compareProps,
|
compareProps,
|
||||||
setDomProps, updateDomProps
|
setDomProps,
|
||||||
} from './DOMPropertiesHandler/DOMPropertiesHandler';
|
} from './DOMPropertiesHandler/DOMPropertiesHandler';
|
||||||
import { isNativeElement, validateProps } from './validators/ValidateProps';
|
import { isNativeElement, validateProps } from './validators/ValidateProps';
|
||||||
import { watchValueChange } from './valueHandler/ValueChangeHandler';
|
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);
|
const props: Object = getPropsWithoutValue(tagName, dom, rawProps);
|
||||||
|
|
||||||
// 初始化DOM属性(不包括value,defaultValue)
|
// 初始化DOM属性(不包括value,defaultValue)
|
||||||
setDomProps(tagName, dom, props);
|
const isNativeTag = isNativeElement(tagName, props);
|
||||||
|
setDomProps(dom, props, isNativeTag, true);
|
||||||
|
|
||||||
if (tagName === 'input' || tagName === 'textarea') {
|
if (tagName === 'input' || tagName === 'textarea') {
|
||||||
// 增加监听value和checked的set、get方法
|
// 增加监听value和checked的set、get方法
|
||||||
|
@ -167,7 +168,7 @@ export function submitDomUpdate(tag: string, vNode: VNode) {
|
||||||
updateCommonProp(element, 'checked', newProps.checked, true);
|
updateCommonProp(element, 'checked', newProps.checked, true);
|
||||||
}
|
}
|
||||||
const isNativeTag = isNativeElement(type, newProps);
|
const isNativeTag = isNativeElement(type, newProps);
|
||||||
updateDomProps(element, changeList, isNativeTag);
|
setDomProps(element, changeList, isNativeTag, false);
|
||||||
updateValue(type, element, newProps);
|
updateValue(type, element, newProps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,15 @@ import { setStyles } from './StyleHandler';
|
||||||
import {
|
import {
|
||||||
listenNonDelegatedEvent
|
listenNonDelegatedEvent
|
||||||
} from '../../event/EventBinding';
|
} from '../../event/EventBinding';
|
||||||
import { isEventProp, isNativeElement } from '../validators/ValidateProps';
|
import { isEventProp } from '../validators/ValidateProps';
|
||||||
|
|
||||||
// 初始化DOM属性
|
// 初始化DOM属性和更新 DOM 属性
|
||||||
export function setDomProps(
|
export function setDomProps(
|
||||||
tagName: string,
|
|
||||||
dom: Element,
|
dom: Element,
|
||||||
props: Object,
|
props: Object,
|
||||||
|
isNativeTag: boolean,
|
||||||
|
isInit: boolean,
|
||||||
): void {
|
): void {
|
||||||
const isNativeTag = isNativeElement(tagName, props);
|
|
||||||
const keysOfProps = Object.keys(props);
|
const keysOfProps = Object.keys(props);
|
||||||
let propName;
|
let propName;
|
||||||
let propVal;
|
let propVal;
|
||||||
|
@ -37,42 +37,7 @@ export function setDomProps(
|
||||||
}
|
}
|
||||||
} else if (propName === 'dangerouslySetInnerHTML') {
|
} else if (propName === 'dangerouslySetInnerHTML') {
|
||||||
dom.innerHTML = propVal.__html;
|
dom.innerHTML = propVal.__html;
|
||||||
} else {
|
} else if (!isInit || (isInit && propVal != null)) {
|
||||||
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 {
|
|
||||||
updateCommonProp(dom, propName, propVal, isNativeTag);
|
updateCommonProp(dom, propName, propVal, isNativeTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue