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

Commit

Permalink
feat(store): add parent relation in page element
Browse files Browse the repository at this point in the history
  • Loading branch information
TheReincarnator committed Dec 8, 2017
1 parent e1a0893 commit aaf999c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/store/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ export class Page {
const pageModel: any = JSON.parse(FileUtils.readFileSync(pagePath, 'utf8'));

this.name = pageModel.name;
this.root = new PageElement(pageModel.root, this.store);
this.root = new PageElement(this.store, pageModel.root);
}
}
17 changes: 14 additions & 3 deletions src/store/page/page_element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ import { Store } from '..';

export class PageElement {
@MobX.observable private children: PageElement[] = [];
private parent: PageElement | undefined;
private patternPath: string;
private pattern?: Pattern;
@MobX.observable private propertyValues: Map<string, PropertyValue> = new Map();

// tslint:disable-next-line:no-any
public constructor(json: any, store: Store) {
public constructor(store: Store, json: any, parent?: PageElement) {
this.parent = parent;

this.patternPath = json['pattern'];
const pattern: Pattern | undefined = store.getPattern(this.patternPath);
if (pattern) {
this.pattern = pattern;
} else {
console.warn(`Ignoring unknown pattern ${this.patternPath}`);
console.warn(`Ignoring unknown pattern "${this.patternPath}"`);
return;
}

Expand All @@ -40,7 +43,7 @@ export class PageElement {
// tslint:disable-next-line:no-any
protected createElementOrValue(json: any, store: Store): PageElement | PropertyValue {
if (json && json['_type'] === 'pattern') {
return new PageElement(json, store);
return new PageElement(store, json, this);
} else {
return json;
}
Expand All @@ -50,6 +53,10 @@ export class PageElement {
return this.children;
}

public getParent(): PageElement | undefined {
return this.parent;
}

public getPattern(): Pattern | undefined {
return this.pattern;
}
Expand All @@ -64,6 +71,10 @@ export class PageElement {
return value;
}

public isRoot(): boolean {
return this.parent === undefined;
}

// tslint:disable-next-line:no-any
public setPropertyValue(id: string, value: any): void {
if (!this.pattern) {
Expand Down

0 comments on commit aaf999c

Please sign in to comment.