Skip to content

Commit

Permalink
fix: 去除无用逻辑 #104
Browse files Browse the repository at this point in the history
  • Loading branch information
army8735 committed Nov 3, 2020
1 parent c920120 commit 162ab22
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 42 deletions.
52 changes: 21 additions & 31 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19232,7 +19232,7 @@
Object.assign(node.__style, style);
}

if (style) {
if (style && style !== target.style) {
Object.assign(target.style, style);
} // 多次调用更新才会有list,一般没有,优化

Expand Down Expand Up @@ -19901,12 +19901,11 @@

if (node.isDestroyed) {
return;
}
} // root特殊处理,检查变更时优先看继承信息

var target; // root特殊处理,检查变更时优先看继承信息

if (node === this) {
target = this.__updateRoot;
var target = this.__updateRoot;

if (target) {
if (img) {
Expand Down Expand Up @@ -19941,7 +19940,7 @@
} else if (!node.hasOwnProperty('__uniqueUpdateId')) {
node.__uniqueUpdateId = uniqueUpdateId; // 大多数情况节点都只有一次更新,所以优化首次直接存在style上,后续存在list

target = updateHash[uniqueUpdateId++] = {
updateHash[uniqueUpdateId++] = {
node: node,
style: style,
origin: origin,
Expand All @@ -19951,23 +19950,24 @@
measure: measure
};
} else if (updateHash.hasOwnProperty(node.__uniqueUpdateId)) {
target = updateHash[node.__uniqueUpdateId];
var _target = updateHash[node.__uniqueUpdateId];

if (img) {
target.img = img;
_target.img = img;
}

if (focus) {
target.focus = focus;
_target.focus = focus;
}

if (measure) {
target.measure = true;
_target.measure = true;
} // 后续存在新建list上,需增加遍历逻辑


target.list = target.list || [];
target.list.push({
_target.list = _target.list || [];

_target.list.push({
style: style,
origin: origin,
overwrite: overwrite
Expand Down Expand Up @@ -20033,41 +20033,31 @@
var isInherit = o.isMeasureInherit(updateHash[__uniqueUpdateId].style); // 是inherit,需要向上查找,从顶部向下递归计算继承信息

if (isInherit) {
var _loop = function _loop() {
while (parent && parent !== _this5) {
var _parent = parent,
__uniqueUpdateId = _parent.__uniqueUpdateId,
_uniqueUpdateId = _parent.__uniqueUpdateId,
currentStyle = _parent.currentStyle;
var isInherit = void 0;

var _isInherit = void 0;

if (parent.hasOwnProperty('__uniqueUpdateId')) {
var style = updateHash[__uniqueUpdateId].style;
measureHash[__uniqueUpdateId] = true;
var style = updateHash[_uniqueUpdateId].style;
measureHash[_uniqueUpdateId] = true;
var temp = o.measureInheritList(style);
temp.forEach(function (k) {
currentStyle[k] = style[k]; // 已经赋值过的删除避免重复

delete style[k];
});
isInherit = !!temp.length;
_isInherit = !!temp.length;
} else {
isInherit = o.isMeasureInherit(currentStyle);
_isInherit = o.isMeasureInherit(currentStyle);
} // 如果parent有inherit存入列表且继续向上,否则跳出循环


if (isInherit) {
if (_isInherit) {
last = parent;
} else {
return "break";
break;
} // 考虑component下的继续往上继承


parent = parent.domParent;
};

while (parent && parent !== _this5) {
var _ret = _loop();

if (_ret === "break") break;
}
} // 自顶向下查找inherit的,利用已有的方法+回调

Expand Down
2 changes: 1 addition & 1 deletion index.js.map

Large diffs are not rendered by default.

14 changes: 4 additions & 10 deletions src/node/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function parseUpdate(renderMode, root, updateHash, target, reflowList, measureLi
if(overwrite && style) {
Object.assign(node.__style, style);
}
if(style) {
if(style && style !== target.style) {
Object.assign(target.style, style);
}
// 多次调用更新才会有list,一般没有,优化
Expand Down Expand Up @@ -626,10 +626,9 @@ class Root extends Dom {
if(node.isDestroyed) {
return;
}
let target;
// root特殊处理,检查变更时优先看继承信息
if(node === this) {
target = this.__updateRoot;
let target = this.__updateRoot;
if(target) {
if(img) {
target.img = img;
Expand Down Expand Up @@ -658,7 +657,7 @@ class Root extends Dom {
else if(!node.hasOwnProperty('__uniqueUpdateId')) {
node.__uniqueUpdateId = uniqueUpdateId;
// 大多数情况节点都只有一次更新,所以优化首次直接存在style上,后续存在list
target = updateHash[uniqueUpdateId++] = {
updateHash[uniqueUpdateId++] = {
node,
style,
origin,
Expand All @@ -669,7 +668,7 @@ class Root extends Dom {
};
}
else if(updateHash.hasOwnProperty(node.__uniqueUpdateId)) {
target = updateHash[node.__uniqueUpdateId];
let target = updateHash[node.__uniqueUpdateId];
if(img) {
target.img = img;
}
Expand Down Expand Up @@ -742,11 +741,6 @@ class Root extends Dom {
let style = updateHash[__uniqueUpdateId].style;
measureHash[__uniqueUpdateId] = true;
let temp = change.measureInheritList(style);
temp.forEach(k => {
currentStyle[k] = style[k];
// 已经赋值过的删除避免重复
delete style[k];
});
isInherit = !!temp.length;
}
else {
Expand Down

0 comments on commit 162ab22

Please sign in to comment.