diff --git a/src/app/components/shared/toggle/toggle.component.scss b/src/app/components/shared/toggle/toggle.component.scss index 23f828d..9ef51ea 100644 --- a/src/app/components/shared/toggle/toggle.component.scss +++ b/src/app/components/shared/toggle/toggle.component.scss @@ -26,6 +26,7 @@ input[type='checkbox'] { -webkit-appearance: none; + -moz-appearance: none; width: 2 * $size; height: $size; diff --git a/src/app/model/block.ts b/src/app/model/block.ts index cf75711..2d49058 100644 --- a/src/app/model/block.ts +++ b/src/app/model/block.ts @@ -4,7 +4,7 @@ import { Node } from '../store/node'; export class Block extends Serializable implements IBlock { constructor(parent: Node, props: IBlock) { - super(parent, props); + super(parent, props, 'Block'); this.onAfterClone(); } diff --git a/src/app/model/page.ts b/src/app/model/page.ts index bad43c3..ba12c64 100644 --- a/src/app/model/page.ts +++ b/src/app/model/page.ts @@ -5,7 +5,7 @@ import { Node } from '../store/node'; export class Page extends Serializable implements IPage { constructor(parent: Node, props: IPage) { - super(parent, props); + super(parent, props, 'Page'); } readonly name: string; diff --git a/src/app/model/serializable.ts b/src/app/model/serializable.ts index 41f0e2b..8eaae74 100644 --- a/src/app/model/serializable.ts +++ b/src/app/model/serializable.ts @@ -2,11 +2,14 @@ import { Cloneable } from '../store/cloneable'; import { Node } from '../store/node'; export class Serializable extends Cloneable { + protected type: string; + private static propertyList: any = {}; static childrenMap: { [type: string]: { childrenConstructor: typeof Serializable; childrenListName: string; + childrenType: string; }; }; @@ -14,29 +17,34 @@ export class Serializable extends Cloneable { // pass } - protected constructor(parent: Node, properties: any) { + protected constructor(parent: Node, properties: any, type: string) { super(parent); - const type = this.constructor.name; - if (!Serializable.propertyList.hasOwnProperty(type)) { - Serializable.propertyList[type] = []; + const compiledType = this.constructor.name; + if (!Serializable.propertyList.hasOwnProperty(compiledType)) { + Serializable.propertyList[compiledType] = []; } for (const property in properties) { if (properties.hasOwnProperty(property)) { const propertyValue = properties[property]; + // This should be ran after the original constructor has finished. + console.log(type); if (property === Serializable.childrenMap[type].childrenListName) { - // This should be ran after the original constructor has finished. new Promise(r => r()).then(() => { for (let child of propertyValue) { - new Serializable.childrenMap[type].childrenConstructor(this, child); + new Serializable.childrenMap[type].childrenConstructor( + this, + child, + Serializable.childrenMap[type].childrenType + ); } }); } else { this[property] = properties[property]; } - if (!Serializable.propertyList[type].includes(property)) { - Serializable.propertyList[type].push(property); + if (!Serializable.propertyList[compiledType].includes(property)) { + Serializable.propertyList[compiledType].push(property); } } } diff --git a/src/app/model/tower.ts b/src/app/model/tower.ts index e0d7a24..7161212 100644 --- a/src/app/model/tower.ts +++ b/src/app/model/tower.ts @@ -9,6 +9,8 @@ import { IColor } from '../interfaces/color'; export type ColoredBlock = Block & { color: IColor }; export class Tower extends Serializable implements ITower { + protected type = 'Tower'; + tags: string[]; name: string; @@ -21,7 +23,7 @@ export class Tower extends Serializable implements ITower { readonly baseColor: IColor; constructor(parent: Node, props: ITower) { - super(parent, props); + super(parent, props, 'Tower'); this.onAfterClone(); } diff --git a/src/app/services/data.service.ts b/src/app/services/data.service.ts index 0bd0771..8c01ba4 100644 --- a/src/app/services/data.service.ts +++ b/src/app/services/data.service.ts @@ -30,15 +30,18 @@ export class DataService extends Root { Serializable.childrenMap = { Page: { childrenListName: 'towers', - childrenConstructor: Tower + childrenConstructor: Tower, + childrenType: 'Tower' }, Tower: { childrenListName: 'blocks', - childrenConstructor: Block + childrenConstructor: Block, + childrenType: 'Block' }, Block: { childrenListName: null, - childrenConstructor: null + childrenConstructor: null, + childrenType: null } }; diff --git a/src/app/services/store.service.ts b/src/app/services/store.service.ts index b574e0c..a4b1596 100644 --- a/src/app/services/store.service.ts +++ b/src/app/services/store.service.ts @@ -114,7 +114,7 @@ export class StoreService { return this.storedData; } - async save(data: T) { + async save(data: T): Promise { this.storedData = data; const stringified = JSON.stringify(this.storedData, null, 2); console.log('save');