Browse Source

无JIRA layout 的updateChildren过程中传递context

master
翠屏山最速下山传说 5 months ago
parent
commit
f0750f646f
  1. 108
      packages/fineui/src/core/wrapper/layout.js

108
packages/fineui/src/core/wrapper/layout.js

@ -1,4 +1,17 @@
import { isNull, isFunction, each, stripEL, keys, isArray, contains, isKey, isOdd, isWidget, isNotNull, has } from "../2.base";
import {
isNull,
isFunction,
each,
stripEL,
keys,
isArray,
contains,
isKey,
isOdd,
isWidget,
isNotNull,
has
} from "../2.base";
import { Widget } from "../4.widget";
import { _lazyCreateWidget, Providers } from "../5.inject";
import { shortcut } from "../decorator";
@ -65,31 +78,31 @@ export class Layout extends Widget {
_init4Scroll() {
switch (this.options.scrollable) {
case true:
case "xy":
this.element.css("overflow", "auto");
return;
case false:
this.element.css("overflow", "hidden");
return;
case "x":
this.element.css({
"overflow-x": "auto",
"overflow-y": "hidden",
});
case true:
case "xy":
this.element.css("overflow", "auto");
return;
case false:
this.element.css("overflow", "hidden");
return;
case "x":
this.element.css({
"overflow-x": "auto",
"overflow-y": "hidden",
});
return;
case "y":
this.element.css({
"overflow-x": "hidden",
"overflow-y": "auto",
});
return;
case "y":
this.element.css({
"overflow-x": "hidden",
"overflow-y": "auto",
});
return;
default :
break;
return;
default :
break;
}
if (this.options.scrollx) {
this.element.css({
@ -190,19 +203,19 @@ export class Layout extends Widget {
}
const className = Object.prototype.toString.call(a);
switch (className) {
case "[object RegExp]":
case "[object String]":
return `${a}` === `${b}`;
case "[object Number]":
if (+a !== +a) {
return +b !== +b;
}
case "[object RegExp]":
case "[object String]":
return `${a}` === `${b}`;
case "[object Number]":
if (+a !== +a) {
return +b !== +b;
}
return +a === 0 ? 1 / +a === 1 / b : +a === +b;
case "[object Date]":
case "[object Boolean]":
return +a === +b;
default:
return +a === 0 ? 1 / +a === 1 / b : +a === +b;
case "[object Date]":
case "[object Boolean]":
return +a === +b;
default:
}
const areArrays = className === "[object Array]";
@ -264,9 +277,9 @@ export class Layout extends Widget {
}
// 不依赖于this.options.items进行更新
_updateItemAt(oldIndex, newIndex, item) {
_updateItemAt(oldIndex, newIndex, item, context) {
const del = this._children[this._getChildName(oldIndex)];
const w = this._newElement(newIndex, item);
const w = this._newElement(newIndex, item, context);
// 需要有个地方临时存一下新建的组件,否则如果直接使用newIndex的话,newIndex位置的元素可能会被用到
this._children[`${this._getChildName(newIndex)}-temp`] = w;
const nextSibling = del.element.next();
@ -317,6 +330,7 @@ export class Layout extends Widget {
return (item._lgap || 0) + (item.lgap || 0);
}
_optimiseItemRgap(item) {
if (Providers.getProvider(SystemProvider.xtype).getLayoutOptimize()) {
return ((!item.type && item.el) ? ((item._rgap || 0) + (item.rgap || 0)) : item._rgap) || 0;
@ -324,6 +338,7 @@ export class Layout extends Widget {
return (item._rgap || 0) + (item.rgap || 0);
}
_optimiseItemTgap(item) {
if (Providers.getProvider(SystemProvider.xtype).getLayoutOptimize()) {
return ((!item.type && item.el) ? ((item._tgap || 0) + (item.tgap || 0)) : item._tgap) || 0;
@ -331,6 +346,7 @@ export class Layout extends Widget {
return (item._tgap || 0) + (item.tgap || 0);
}
_optimiseItemBgap(item) {
if (Providers.getProvider(SystemProvider.xtype).getLayoutOptimize()) {
return ((!item.type && item.el) ? ((item._bgap || 0) + (item.bgap || 0)) : item._bgap) || 0;
@ -338,6 +354,7 @@ export class Layout extends Widget {
return (item._bgap || 0) + (item.bgap || 0);
}
_optimiseItemHgap(item) {
if (Providers.getProvider(SystemProvider.xtype).getLayoutOptimize()) {
return ((!item.type && item.el) ? ((item._hgap || 0) + (item.hgap || 0)) : item._hgap) || 0;
@ -345,6 +362,7 @@ export class Layout extends Widget {
return (item._hgap || 0) + (item.hgap || 0);
}
_optimiseItemVgap(item) {
if (Providers.getProvider(SystemProvider.xtype).getLayoutOptimize()) {
return ((!item.type && item.el) ? ((item._vgap || 0) + (item.vgap || 0)) : item._vgap) || 0;
@ -552,7 +570,7 @@ export class Layout extends Widget {
});
}
patchItem(oldVnode, vnode, oldIndex, newIndex) {
patchItem(oldVnode, vnode, oldIndex, newIndex, context) {
const shouldUpdate = this.shouldUpdateItem(oldIndex, vnode);
const child = this._children[this._getChildName(oldIndex)];
if (shouldUpdate) {
@ -564,7 +582,7 @@ export class Layout extends Widget {
// if (child.update) {
// return child.update(this._getOptions(vnode));
// }
return this._updateItemAt(oldIndex, newIndex, vnode);
return this._updateItemAt(oldIndex, newIndex, vnode, context);
}
}
@ -665,26 +683,26 @@ export class Layout extends Widget {
} else if (isNull(oldEndVnode)) {
oldEndVnode = oldCh[--oldEndIdx];
} else if (sameVnode(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx)) {
const willUpdate = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx);
const willUpdate = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx, context);
updated = willUpdate || updated;
children[isNull(oldStartVnode.key) ? oldStartIdx : oldStartVnode.key] = willUpdate ? this._children[`${this._getChildName(newStartIdx)}-temp`] : this._children[this._getChildName(oldStartIdx)];
oldStartVnode = oldCh[++oldStartIdx];
newStartVnode = newCh[++newStartIdx];
} else if (sameVnode(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx)) {
const willUpdate = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx);
const willUpdate = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx, context);
updated = willUpdate || updated;
children[isNull(oldEndVnode.key) ? oldEndIdx : oldEndVnode.key] = willUpdate ? this._children[`${this._getChildName(newEndIdx)}-temp`] : this._children[this._getChildName(oldEndIdx)];
oldEndVnode = oldCh[--oldEndIdx];
newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldStartVnode, newEndVnode)) {
const willUpdate = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx, newStartIdx);
const willUpdate = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx, newStartIdx, context);
updated = willUpdate || updated;
children[isNull(oldStartVnode.key) ? oldStartIdx : oldStartVnode.key] = willUpdate ? this._children[`${this._getChildName(newStartIdx)}-temp`] : this._children[this._getChildName(oldStartIdx)];
insertBefore(oldStartVnode, oldEndVnode, true);
oldStartVnode = oldCh[++oldStartIdx];
newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldEndVnode, newStartVnode)) {
const willUpdate = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx, newEndIdx);
const willUpdate = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx, newEndIdx, context);
updated = willUpdate || updated;
children[isNull(oldEndVnode) ? oldEndIdx : oldEndVnode.key] = willUpdate ? this._children[`${this._getChildName(newEndIdx)}-temp`] : this._children[this._getChildName(oldEndIdx)];
insertBefore(oldEndVnode, oldStartVnode);
@ -697,7 +715,7 @@ export class Layout extends Widget {
insertBefore(node, oldStartVnode);
} else { // 如果新节点在旧节点区间中存在就复用一下
const sameOldIndex = sameOldVnode[1];
const willUpdate = this.patchItem(sameOldVnode[0], newStartVnode, sameOldIndex, newStartIdx);
const willUpdate = this.patchItem(sameOldVnode[0], newStartVnode, sameOldIndex, newStartIdx, context);
updated = willUpdate || updated;
children[isNull(sameOldVnode[0].key) ? newStartIdx : sameOldVnode[0].key] = willUpdate ? this._children[`${this._getChildName(newStartIdx)}-temp`] : this._children[this._getChildName(sameOldIndex)];
oldCh[sameOldIndex] = undefined;

Loading…
Cancel
Save