(oldVnode, vnode)
| 10513 | * 更新真实dom的props属性 |
| 10514 | * */ |
| 10515 | function updateDOMProps(oldVnode, vnode) { |
| 10516 | |
| 10517 | if (isUndef(oldVnode.data.domProps) && isUndef(vnode.data.domProps)) { |
| 10518 | return |
| 10519 | } |
| 10520 | var key, cur; |
| 10521 | var elm = vnode.elm; |
| 10522 | var oldProps = oldVnode.data.domProps || {}; //获取旧的props属性 |
| 10523 | var props = vnode.data.domProps || {}; //获取新的props |
| 10524 | // clone observed objects, as the user probably wants to mutate it |
| 10525 | //克隆观察到的对象,因为用户可能希望对其进行修改 |
| 10526 | if (isDef(props.__ob__)) { //如果是props添加了观察者,重新克隆他,这样就可以修改了 |
| 10527 | props = vnode.data.domProps = extend({}, props); |
| 10528 | } |
| 10529 | consolelog(props) |
| 10530 | consolelog(oldProps) |
| 10531 | |
| 10532 | for (key in oldProps) { //循环旧的props属性,如果没有定义了 就给空 |
| 10533 | if (isUndef(props[key])) { |
| 10534 | elm[key] = ''; |
| 10535 | } |
| 10536 | } |
| 10537 | for (key in props) { //循环新的props属性 |
| 10538 | cur = props[key]; //获取props 的值 |
| 10539 | // ignore children if the node has textContent or innerHTML, |
| 10540 | // as these will throw away existing DOM nodes and cause removal errors |
| 10541 | // on subsequent patches (#3360) |
| 10542 | //忽略子节点,如果节点有textContent或innerHTML, |
| 10543 | //因为这将丢弃现有的DOM节点并导致删除错误 |
| 10544 | //其后的修补程式(#3360) |
| 10545 | if ( |
| 10546 | key === 'textContent' || |
| 10547 | key === 'innerHTML' |
| 10548 | ) { |
| 10549 | if (vnode.children) { |
| 10550 | vnode.children.length = 0; |
| 10551 | } |
| 10552 | if (cur === oldProps[key]) { |
| 10553 | continue |
| 10554 | } |
| 10555 | // #6601 work around Chrome version <= 55 bug where single textNode |
| 10556 | // replaced by innerHTML/textContent retains its parentNode property |
| 10557 | // #6601解决Chrome版本<= 55的bug,其中只有一个textNode |
| 10558 | //被innerHTML/textContent替换后,保留了它的parentNode属性 |
| 10559 | if (elm.childNodes.length === 1) { //文本节点 |
| 10560 | elm.removeChild(elm.childNodes[0]); |
| 10561 | } |
| 10562 | } |
| 10563 | |
| 10564 | if (key === 'value') { |
| 10565 | // store value as _value as well since |
| 10566 | // non-string values will be stringified |
| 10567 | //将value存储为_value以及since |
| 10568 | //非字符串值将被字符串化 |
| 10569 | elm._value = cur; |
| 10570 | // avoid resetting cursor position when value is the same |
| 10571 | // 当值相同时,避免重置光标位置 |
| 10572 | var strCur = isUndef(cur) ? '' : String(cur); //转义成字符串 |
nothing calls this directly
no test coverage detected