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 48005ae commit 7c69ded
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
17 changes: 9 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3861,7 +3861,7 @@
parent = node.parent;
var parentComputedStyle = !isHost && parent.computedStyle;
o.MEASURE_KEY_SET.forEach(function (k) {
var v = currentStyle[k];
var v = currentStyle[k]; // console.log(node.tagName, k, v);

if (v.unit === INHERIT$1) {
computedStyle[k] = isHost ? reset.INHERIT[k] : parentComputedStyle[k];
Expand Down Expand Up @@ -19982,7 +19982,6 @@
value: function __checkUpdate(renderMode, ctx, width, height) {
var _this5 = this;

uniqueUpdateId = 0;
var measureList = [];
var reflowList = [];
var cacheHash = {};
Expand All @@ -19998,12 +19997,17 @@
} // 汇总处理每个节点


this.__updateHash = {};
var keys = Object.keys(updateHash);
keys.forEach(function (k) {
parseUpdate(renderMode, _this5, updateHash, updateHash[k], reflowList, measureList, cacheHash, cacheList);
});
}); // 先做一部分reset避免下面measureList干扰

this.__reflowList = reflowList;
uniqueUpdateId = 0;
this.__updateHash = {};
cacheList.forEach(function (item) {
delete item.__uniqueUpdateId;
});
/**
* 遍历每项节点,计算测量信息,节点向上向下查找继承信息,如果parent也是继承,先计算parent的
* 过程中可能会出现重复,因此节点上记录一个临时标防止重复递归
Expand All @@ -20028,10 +20032,10 @@
var _parent = parent,
__uniqueUpdateId = _parent.__uniqueUpdateId,
currentStyle = _parent.currentStyle;
var style = updateHash[__uniqueUpdateId].style;
var isInherit = void 0;

if (parent.hasOwnProperty('__uniqueUpdateId')) {
var style = updateHash[__uniqueUpdateId].style;
measureHash[__uniqueUpdateId] = true;
var temp = o.measureInheritList(style);
temp.forEach(function (k) {
Expand Down Expand Up @@ -20073,9 +20077,6 @@
keys.forEach(function (k) {
delete updateHash[k].node.__uniqueUpdateId;
});
cacheList.forEach(function (item) {
delete item.__uniqueUpdateId;
});
}
/**
* 除首次外每次刷新前检查reflow列表,计算需要reflow的节点局部重新布局
Expand Down
2 changes: 1 addition & 1 deletion index.js.map

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions src/node/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,6 @@ class Root extends Dom {
* @private
*/
__checkUpdate(renderMode, ctx, width, height) {
uniqueUpdateId = 0;
let measureList = [];
let reflowList = [];
let cacheHash = {};
Expand All @@ -707,12 +706,17 @@ class Root extends Dom {
this.__checkRoot(width, height);
}
// 汇总处理每个节点
this.__updateHash = {};
let keys = Object.keys(updateHash);
keys.forEach(k => {
parseUpdate(renderMode, this, updateHash, updateHash[k], reflowList, measureList, cacheHash, cacheList);
});
// 先做一部分reset避免下面measureList干扰
this.__reflowList = reflowList;
uniqueUpdateId = 0;
this.__updateHash = {};
cacheList.forEach(item => {
delete item.__uniqueUpdateId;
});
/**
* 遍历每项节点,计算测量信息,节点向上向下查找继承信息,如果parent也是继承,先计算parent的
* 过程中可能会出现重复,因此节点上记录一个临时标防止重复递归
Expand All @@ -731,9 +735,9 @@ class Root extends Dom {
if(isInherit) {
while(parent && parent !== this) {
let { __uniqueUpdateId, currentStyle } = parent;
let style = updateHash[__uniqueUpdateId].style;
let isInherit;
if(parent.hasOwnProperty('__uniqueUpdateId')) {
let style = updateHash[__uniqueUpdateId].style;
measureHash[__uniqueUpdateId] = true;
let temp = change.measureInheritList(style);
temp.forEach(k => {
Expand Down Expand Up @@ -768,9 +772,6 @@ class Root extends Dom {
keys.forEach(k => {
delete updateHash[k].node.__uniqueUpdateId;
});
cacheList.forEach(item => {
delete item.__uniqueUpdateId;
});
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/style/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ function computeMeasure(node, isHost) {
let parentComputedStyle = !isHost && parent.computedStyle;
change.MEASURE_KEY_SET.forEach(k => {
let v = currentStyle[k];
// console.log(node.tagName, k, v);
if(v.unit === INHERIT) {
computedStyle[k] = isHost ? reset.INHERIT[k] : parentComputedStyle[k];
}
Expand Down

0 comments on commit 7c69ded

Please sign in to comment.