mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2025-04-18 22:00:22 +08:00
fix: updating a non-existing property will add a new property to the component
This commit is contained in:
parent
d3d0030f96
commit
f63c105786
@ -33,12 +33,17 @@ describe('update component property', () => {
|
||||
const origin = appModel.toSchema();
|
||||
const text1 = appModel.getComponentById('text1' as any);
|
||||
text1!.updateComponentProperty('value', { raw: 'hello', format: 'md' });
|
||||
text1!.updateComponentProperty('newProperty', "a property that didn't exist before");
|
||||
const newSchema = appModel.toSchema();
|
||||
|
||||
it('update component properties', () => {
|
||||
expect(newSchema[5].properties.value).toEqual({ raw: 'hello', format: 'md' });
|
||||
});
|
||||
|
||||
it("update a new property that component don't have",()=>{
|
||||
expect(newSchema[5].properties.newProperty).toEqual("a property that didn't exist before");
|
||||
})
|
||||
|
||||
it('keep immutable after updating component properties', () => {
|
||||
expect(origin).not.toBe(newSchema);
|
||||
expect(origin[0]).toBe(newSchema[0]);
|
||||
|
@ -146,7 +146,11 @@ export class ComponentModel implements IComponentModel {
|
||||
}
|
||||
|
||||
updateComponentProperty(propertyName: string, value: any) {
|
||||
this.properties[propertyName].update(value);
|
||||
if (!Reflect.has(this.properties, propertyName)) {
|
||||
this.properties[propertyName] = new FieldModel(value)
|
||||
} else {
|
||||
this.properties[propertyName].update(value);
|
||||
}
|
||||
this._isDirty = true;
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,8 @@ export class ModifyComponentPropertiesLeafOperation extends BaseLeafOperation<Mo
|
||||
const appModel = new AppModel(prev);
|
||||
const component = appModel.getComponentById(this.context.componentId as ComponentId);
|
||||
if (component) {
|
||||
for (const property in component.properties) {
|
||||
const oldValue = component.properties[property].value;
|
||||
for (const property in this.context.properties) {
|
||||
const oldValue = component.properties[property]?.value;
|
||||
// assign previous data
|
||||
this.previousState[property] = oldValue;
|
||||
let newValue = this.context.properties[property];
|
||||
|
Loading…
x
Reference in New Issue
Block a user