Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
fix: hold on to legacy prop references
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed Sep 10, 2018
1 parent cd0dd79 commit ead0750
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/model/element/element-property/element-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions src/model/element/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,6 +70,12 @@ export class Element {

@Mobx.observable private selected: boolean;

/**
/* TODO: Remove before beta
/* Keep backward compat
/*/
private readonly LEGACY_elementPropertyIds: Map<string, string> = new Map();

@Mobx.computed
private get mayHighiglight(): boolean {
if (!this.page || !this.page.getActive()) {
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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);
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/types/serialized-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down

0 comments on commit ead0750

Please sign in to comment.