From ead07507524725ec8db8ffa3884fcd55f047dd8f Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Sat, 11 Aug 2018 18:21:00 +0200 Subject: [PATCH] fix: hold on to legacy prop references --- .../element/element-property/element-property.ts | 6 ++++-- src/model/element/element.ts | 16 +++++++++++++--- src/types/serialized-model.ts | 5 +++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/model/element/element-property/element-property.ts b/src/model/element/element-property/element-property.ts index 49aeeffbd..4d8882744 100644 --- a/src/model/element/element-property/element-property.ts +++ b/src/model/element/element-property/element-property.ts @@ -81,11 +81,13 @@ export class ElementProperty { public static fromPatternProperty( patternProperty: AnyPatternProperty, - context: ElementPropertyContext + context: ElementPropertyContext & { LEGACY_ID?: string } ): ElementProperty { return new ElementProperty( { - id: uuid.v4(), + id: context.LEGACY_ID + ? context.LEGACY_ID + : [context.element.getId(), patternProperty.getId()].join('-'), patternPropertyId: patternProperty.getId() }, context diff --git a/src/model/element/element.ts b/src/model/element/element.ts index 57184cdf0..3e097973f 100644 --- a/src/model/element/element.ts +++ b/src/model/element/element.ts @@ -21,8 +21,7 @@ export interface ElementInit { open: boolean; patternId: string; placeholderHighlighted: boolean; - // tslint:disable-next-line:no-any - propertyValues: [string, any][]; + propertyValues: [string, Types.ElementPropertyValue][]; role?: Types.ElementRole; selected: boolean; setDefaults?: boolean; @@ -71,6 +70,12 @@ export class Element { @Mobx.observable private selected: boolean; + /** + /* TODO: Remove before beta + /* Keep backward compat + /*/ + private readonly LEGACY_elementPropertyIds: Map = new Map(); + @Mobx.computed private get mayHighiglight(): boolean { if (!this.page || !this.page.getActive()) { @@ -130,6 +135,7 @@ export class Element { private get properties(): ElementProperty[] { return this.patternProperties.map(patternProperty => ElementProperty.fromPatternProperty(patternProperty, { + LEGACY_ID: this.LEGACY_elementPropertyIds.get(patternProperty.getId()), element: this, project: this.project }) @@ -186,10 +192,14 @@ export class Element { context ); - // Keep backward compat + /** + * TODO: Remove before beta + * Keep backward compat + */ if (Array.isArray(serialized.properties)) { serialized.properties.forEach((property: Types.LegacySerializedElementProperty) => { element.setPropertyValue(property.patternPropertyId, property.value); + element.LEGACY_elementPropertyIds.set(property.patternPropertyId, property.id); }); } diff --git a/src/types/serialized-model.ts b/src/types/serialized-model.ts index 29998c457..1af05c502 100644 --- a/src/types/serialized-model.ts +++ b/src/types/serialized-model.ts @@ -139,6 +139,11 @@ export interface SerializedElement { selected: boolean; } +export interface SerializedElementValue { + id: string; + value: Types.ElementPropertyValue; +} + export interface SerializedElementContent { model: Types.ModelName.ElementContent; elementIds: string[];