Skip to content

Commit 035c213

Browse files
liujupingJackLian
authored andcommitted
fix: fix that the prop model is not reused and the update is not triggered
1 parent d82bcfd commit 035c213

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

packages/designer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"license": "MIT",
1717
"dependencies": {
18+
"@alilc/build-plugin-lce": "^0.0.4-beta.2",
1819
"@alilc/lowcode-editor-core": "1.1.7",
1920
"@alilc/lowcode-types": "1.1.7",
2021
"@alilc/lowcode-utils": "1.1.7",

packages/designer/src/document/node/props/prop.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,13 @@ export class Prop implements IProp, IPropParent {
148148

149149
@obx.shallow private _items: IProp[] | null = null;
150150

151-
@obx.shallow private _maps: Map<string | number, IProp> | null = null;
152-
153151
/**
154-
* 作为 _maps 的一层缓存机制,主要是复用部分已存在的 Prop,保持响应式关系,比如:
152+
* 作为一层缓存机制,主要是复用部分已存在的 Prop,保持响应式关系,比如:
155153
* 当前 Prop#_value 值为 { a: 1 },当调用 setValue({ a: 2 }) 时,所有原来的子 Prop 均被销毁,
156154
* 导致假如外部有 mobx reaction(常见于 observer),此时响应式链路会被打断,
157155
* 因为 reaction 监听的是原 Prop(a) 的 _value,而不是新 Prop(a) 的 _value。
158156
*/
159-
private _prevMaps: Map<string | number, IProp> | null = null;
157+
@obx.shallow private _maps: Map<string | number, IProp> | null = null;
160158

161159
/**
162160
* 构造 items 属性,同时构造 maps 属性
@@ -171,8 +169,8 @@ export class Prop implements IProp, IPropParent {
171169
data.forEach((item: any, idx: number) => {
172170
items = items || [];
173171
let prop;
174-
if (this._prevMaps?.has(idx.toString())) {
175-
prop = this._prevMaps.get(idx.toString())!;
172+
if (this._maps?.has(idx.toString())) {
173+
prop = this._maps.get(idx.toString())!;
176174
prop.setValue(item);
177175
} else {
178176
prop = new Prop(this, item, idx);
@@ -187,8 +185,8 @@ export class Prop implements IProp, IPropParent {
187185
const keys = Object.keys(data);
188186
for (const key of keys) {
189187
let prop: IProp;
190-
if (this._prevMaps?.has(key)) {
191-
prop = this._prevMaps.get(key)!;
188+
if (this._maps?.has(key)) {
189+
prop = this._maps.get(key)!;
192190
prop.setValue(data[key]);
193191
} else {
194192
prop = new Prop(this, data[key], key);
@@ -419,8 +417,6 @@ export class Prop implements IProp, IPropParent {
419417
items.forEach((prop) => prop.purge());
420418
}
421419
this._items = null;
422-
this._prevMaps = this._maps;
423-
this._maps = null;
424420
if (this._type !== 'slot' && this._slotNode) {
425421
this._slotNode.remove();
426422
this._slotNode = undefined;

packages/designer/tests/document/node/props/prop.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ describe('Prop 类测试', () => {
379379
prop.dispose();
380380

381381
expect(prop._items).toBeNull();
382-
expect(prop._maps).toBeNull();
383382
});
384383
});
385384

0 commit comments

Comments
 (0)