Skip to content

Commit

Permalink
fix: 回退struct代理,updater的sr引用 #104
Browse files Browse the repository at this point in the history
  • Loading branch information
army8735 committed Nov 5, 2020
1 parent f9135eb commit bf390d3
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 54 deletions.
68 changes: 41 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14758,25 +14758,23 @@
}
}
});
});
['__struct'].forEach(function (fn) {
Object.defineProperty(Component$1.prototype, fn, {
get: function get() {
var sr = this.shadowRoot;

if (sr) {
return sr[fn];
}
},
set: function set(v) {
var sr = this.shadowRoot;
}); // ['__struct'].forEach(fn => {
// Object.defineProperty(Component.prototype, fn, {
// get() {
// let sr = this.shadowRoot;
// if(sr) {
// return sr[fn];
// }
// },
// set(v) {
// let sr = this.shadowRoot;
// if(sr) {
// sr[fn] = v;
// }
// },
// });
// });

if (sr) {
sr[fn] = v;
}
}
});
});
['__layout', '__layoutAbs', '__tryLayInline', '__offsetX', '__offsetY', '__calAutoBasis', '__calMp', '__calAbs', '__renderAsMask', '__renderByMask', '__mp', 'animate', 'removeAnimate', 'clearAnimate', 'updateStyle', 'deepScan', '__cancelCache', '__applyCache', '__mergeBbox', '__structure', '__modifyStruct'].forEach(function (fn) {
Component$1.prototype[fn] = function () {
var sr = this.shadowRoot;
Expand Down Expand Up @@ -15514,6 +15512,11 @@
index = _this$__struct.index,
total = _this$__struct.total;
var zIndexChildren = this.__zIndexChildren = genZIndexChildren(this);

if (zIndexChildren.length === 1) {
return;
}

zIndexChildren.forEach(function (child, i) {
child.__struct.childIndex = i;
}); // 按直接子节点划分为相同数量的若干段进行排序
Expand Down Expand Up @@ -18204,6 +18207,7 @@
cp.__state = state;
cp.__nextState = null;
var oldS = cp.shadow;
var oldSr = cp.shadowRoot;
var oldJson = cp.__cd;
var json = builder.flattenJson(cp.render()); // 对比新老render()返回的内容,更新后重新生成sr

Expand All @@ -18212,18 +18216,28 @@
cp.__init(json); // 为了局部dom布局需要知道老的css信息


var s = cp.shadow;
var sr = cp.shadowRoot;

if (s instanceof Xom$2) {
s.__width = oldS.width;
s.__height = oldS.height;
s.__computedStyle = oldS.computedStyle;
s.__layoutData = oldS.layoutData;
} else {
s.__parent = oldS.parent;
if (sr instanceof Xom$2) {
sr.__width = oldSr.width;
sr.__height = oldSr.height;
sr.__computedStyle = oldSr.computedStyle;
sr.__layoutData = oldSr.layoutData;
}

s.__struct = oldS.__struct;
sr.__parent = oldSr.parent;
sr.__struct = oldSr.__struct; // let s = cp.shadow;
// if(s instanceof Xom) {
// s.__width = oldS.width;
// s.__height = oldS.height;
// s.__computedStyle = oldS.computedStyle;
// s.__layoutData = oldS.layoutData;
// }
// else {
// s.__parent = oldS.parent;
// }
// s.__struct = oldS.__struct;

updateList.push(cp); // 老的需回收,diff会生成新的dom,唯一列外是cp直接返回一个没变化的cp

if (!util.isObject(json) || !json.placeholder) {
Expand Down
2 changes: 1 addition & 1 deletion index.js.map

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions src/node/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,22 +284,22 @@ Object.keys(change.GEOM).concat([
});
});

['__struct'].forEach(fn => {
Object.defineProperty(Component.prototype, fn, {
get() {
let sr = this.shadowRoot;
if(sr) {
return sr[fn];
}
},
set(v) {
let sr = this.shadowRoot;
if(sr) {
sr[fn] = v;
}
},
});
});
// ['__struct'].forEach(fn => {
// Object.defineProperty(Component.prototype, fn, {
// get() {
// let sr = this.shadowRoot;
// if(sr) {
// return sr[fn];
// }
// },
// set(v) {
// let sr = this.shadowRoot;
// if(sr) {
// sr[fn] = v;
// }
// },
// });
// });

[
'__layout',
Expand Down
3 changes: 3 additions & 0 deletions src/node/Dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ class Dom extends Xom {
__updateStruct(structs) {
let { index, total } = this.__struct;
let zIndexChildren = this.__zIndexChildren = genZIndexChildren(this);
if(zIndexChildren.length === 1) {
return;
}
zIndexChildren.forEach((child, i) => {
child.__struct.childIndex = i;
});
Expand Down
30 changes: 20 additions & 10 deletions src/util/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,33 @@ function updateCp(cp, props, state) {
cp.__state = state;
cp.__nextState = null;
let oldS = cp.shadow;
let oldSr = cp.shadowRoot;
let oldJson = cp.__cd;
let json = builder.flattenJson(cp.render());
// 对比新老render()返回的内容,更新后重新生成sr
diffSr(oldS, oldJson, json);
cp.__init(json);
// 为了局部dom布局需要知道老的css信息
let s = cp.shadow;
if(s instanceof Xom) {
s.__width = oldS.width;
s.__height = oldS.height;
s.__computedStyle = oldS.computedStyle;
s.__layoutData = oldS.layoutData;
let sr = cp.shadowRoot;
if(sr instanceof Xom) {
sr.__width = oldSr.width;
sr.__height = oldSr.height;
sr.__computedStyle = oldSr.computedStyle;
sr.__layoutData = oldSr.layoutData;
}
else {
s.__parent = oldS.parent;
}
s.__struct = oldS.__struct;
sr.__parent = oldSr.parent;
sr.__struct = oldSr.__struct;
// let s = cp.shadow;
// if(s instanceof Xom) {
// s.__width = oldS.width;
// s.__height = oldS.height;
// s.__computedStyle = oldS.computedStyle;
// s.__layoutData = oldS.layoutData;
// }
// else {
// s.__parent = oldS.parent;
// }
// s.__struct = oldS.__struct;
updateList.push(cp);
// 老的需回收,diff会生成新的dom,唯一列外是cp直接返回一个没变化的cp
if(!util.isObject(json) || !json.placeholder) {
Expand Down

0 comments on commit bf390d3

Please sign in to comment.