mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 03:01:16 +00:00
fix: fix that the prop model is not reused and the update is not triggered
This commit is contained in:
parent
d82bcfdf2a
commit
035c213b16
@ -15,6 +15,7 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@alilc/build-plugin-lce": "^0.0.4-beta.2",
|
||||||
"@alilc/lowcode-editor-core": "1.1.7",
|
"@alilc/lowcode-editor-core": "1.1.7",
|
||||||
"@alilc/lowcode-types": "1.1.7",
|
"@alilc/lowcode-types": "1.1.7",
|
||||||
"@alilc/lowcode-utils": "1.1.7",
|
"@alilc/lowcode-utils": "1.1.7",
|
||||||
|
|||||||
@ -148,15 +148,13 @@ export class Prop implements IProp, IPropParent {
|
|||||||
|
|
||||||
@obx.shallow private _items: IProp[] | null = null;
|
@obx.shallow private _items: IProp[] | null = null;
|
||||||
|
|
||||||
@obx.shallow private _maps: Map<string | number, IProp> | null = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 作为 _maps 的一层缓存机制,主要是复用部分已存在的 Prop,保持响应式关系,比如:
|
* 作为一层缓存机制,主要是复用部分已存在的 Prop,保持响应式关系,比如:
|
||||||
* 当前 Prop#_value 值为 { a: 1 },当调用 setValue({ a: 2 }) 时,所有原来的子 Prop 均被销毁,
|
* 当前 Prop#_value 值为 { a: 1 },当调用 setValue({ a: 2 }) 时,所有原来的子 Prop 均被销毁,
|
||||||
* 导致假如外部有 mobx reaction(常见于 observer),此时响应式链路会被打断,
|
* 导致假如外部有 mobx reaction(常见于 observer),此时响应式链路会被打断,
|
||||||
* 因为 reaction 监听的是原 Prop(a) 的 _value,而不是新 Prop(a) 的 _value。
|
* 因为 reaction 监听的是原 Prop(a) 的 _value,而不是新 Prop(a) 的 _value。
|
||||||
*/
|
*/
|
||||||
private _prevMaps: Map<string | number, IProp> | null = null;
|
@obx.shallow private _maps: Map<string | number, IProp> | null = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造 items 属性,同时构造 maps 属性
|
* 构造 items 属性,同时构造 maps 属性
|
||||||
@ -171,8 +169,8 @@ export class Prop implements IProp, IPropParent {
|
|||||||
data.forEach((item: any, idx: number) => {
|
data.forEach((item: any, idx: number) => {
|
||||||
items = items || [];
|
items = items || [];
|
||||||
let prop;
|
let prop;
|
||||||
if (this._prevMaps?.has(idx.toString())) {
|
if (this._maps?.has(idx.toString())) {
|
||||||
prop = this._prevMaps.get(idx.toString())!;
|
prop = this._maps.get(idx.toString())!;
|
||||||
prop.setValue(item);
|
prop.setValue(item);
|
||||||
} else {
|
} else {
|
||||||
prop = new Prop(this, item, idx);
|
prop = new Prop(this, item, idx);
|
||||||
@ -187,8 +185,8 @@ export class Prop implements IProp, IPropParent {
|
|||||||
const keys = Object.keys(data);
|
const keys = Object.keys(data);
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
let prop: IProp;
|
let prop: IProp;
|
||||||
if (this._prevMaps?.has(key)) {
|
if (this._maps?.has(key)) {
|
||||||
prop = this._prevMaps.get(key)!;
|
prop = this._maps.get(key)!;
|
||||||
prop.setValue(data[key]);
|
prop.setValue(data[key]);
|
||||||
} else {
|
} else {
|
||||||
prop = new Prop(this, data[key], key);
|
prop = new Prop(this, data[key], key);
|
||||||
@ -419,8 +417,6 @@ export class Prop implements IProp, IPropParent {
|
|||||||
items.forEach((prop) => prop.purge());
|
items.forEach((prop) => prop.purge());
|
||||||
}
|
}
|
||||||
this._items = null;
|
this._items = null;
|
||||||
this._prevMaps = this._maps;
|
|
||||||
this._maps = null;
|
|
||||||
if (this._type !== 'slot' && this._slotNode) {
|
if (this._type !== 'slot' && this._slotNode) {
|
||||||
this._slotNode.remove();
|
this._slotNode.remove();
|
||||||
this._slotNode = undefined;
|
this._slotNode = undefined;
|
||||||
|
|||||||
@ -379,7 +379,6 @@ describe('Prop 类测试', () => {
|
|||||||
prop.dispose();
|
prop.dispose();
|
||||||
|
|
||||||
expect(prop._items).toBeNull();
|
expect(prop._items).toBeNull();
|
||||||
expect(prop._maps).toBeNull();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user