fix: fix that the prop model is not reused and the update is not triggered

This commit is contained in:
liujuping 2023-05-31 18:18:52 +08:00 committed by 林熠
parent d82bcfdf2a
commit 035c213b16
3 changed files with 7 additions and 11 deletions

View File

@ -15,6 +15,7 @@
},
"license": "MIT",
"dependencies": {
"@alilc/build-plugin-lce": "^0.0.4-beta.2",
"@alilc/lowcode-editor-core": "1.1.7",
"@alilc/lowcode-types": "1.1.7",
"@alilc/lowcode-utils": "1.1.7",

View File

@ -148,15 +148,13 @@ export class Prop implements IProp, IPropParent {
@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
* mobx reaction observer
* 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
@ -171,8 +169,8 @@ export class Prop implements IProp, IPropParent {
data.forEach((item: any, idx: number) => {
items = items || [];
let prop;
if (this._prevMaps?.has(idx.toString())) {
prop = this._prevMaps.get(idx.toString())!;
if (this._maps?.has(idx.toString())) {
prop = this._maps.get(idx.toString())!;
prop.setValue(item);
} else {
prop = new Prop(this, item, idx);
@ -187,8 +185,8 @@ export class Prop implements IProp, IPropParent {
const keys = Object.keys(data);
for (const key of keys) {
let prop: IProp;
if (this._prevMaps?.has(key)) {
prop = this._prevMaps.get(key)!;
if (this._maps?.has(key)) {
prop = this._maps.get(key)!;
prop.setValue(data[key]);
} else {
prop = new Prop(this, data[key], key);
@ -419,8 +417,6 @@ export class Prop implements IProp, IPropParent {
items.forEach((prop) => prop.purge());
}
this._items = null;
this._prevMaps = this._maps;
this._maps = null;
if (this._type !== 'slot' && this._slotNode) {
this._slotNode.remove();
this._slotNode = undefined;

View File

@ -379,7 +379,6 @@ describe('Prop 类测试', () => {
prop.dispose();
expect(prop._items).toBeNull();
expect(prop._maps).toBeNull();
});
});