Fix optimization issue

This commit is contained in:
schmelczerandras 2019-09-01 18:47:31 +02:00
parent db6a31dd85
commit d89b43e055
7 changed files with 29 additions and 15 deletions

View file

@ -26,6 +26,7 @@
input[type='checkbox'] { input[type='checkbox'] {
-webkit-appearance: none; -webkit-appearance: none;
-moz-appearance: none;
width: 2 * $size; width: 2 * $size;
height: $size; height: $size;

View file

@ -4,7 +4,7 @@ import { Node } from '../store/node';
export class Block extends Serializable implements IBlock { export class Block extends Serializable implements IBlock {
constructor(parent: Node, props: IBlock) { constructor(parent: Node, props: IBlock) {
super(parent, props); super(parent, props, 'Block');
this.onAfterClone(); this.onAfterClone();
} }

View file

@ -5,7 +5,7 @@ import { Node } from '../store/node';
export class Page extends Serializable implements IPage { export class Page extends Serializable implements IPage {
constructor(parent: Node, props: IPage) { constructor(parent: Node, props: IPage) {
super(parent, props); super(parent, props, 'Page');
} }
readonly name: string; readonly name: string;

View file

@ -2,11 +2,14 @@ import { Cloneable } from '../store/cloneable';
import { Node } from '../store/node'; import { Node } from '../store/node';
export class Serializable extends Cloneable { export class Serializable extends Cloneable {
protected type: string;
private static propertyList: any = {}; private static propertyList: any = {};
static childrenMap: { static childrenMap: {
[type: string]: { [type: string]: {
childrenConstructor: typeof Serializable; childrenConstructor: typeof Serializable;
childrenListName: string; childrenListName: string;
childrenType: string;
}; };
}; };
@ -14,29 +17,34 @@ export class Serializable extends Cloneable {
// pass // pass
} }
protected constructor(parent: Node, properties: any) { protected constructor(parent: Node, properties: any, type: string) {
super(parent); super(parent);
const type = this.constructor.name; const compiledType = this.constructor.name;
if (!Serializable.propertyList.hasOwnProperty(type)) { if (!Serializable.propertyList.hasOwnProperty(compiledType)) {
Serializable.propertyList[type] = []; Serializable.propertyList[compiledType] = [];
} }
for (const property in properties) { for (const property in properties) {
if (properties.hasOwnProperty(property)) { if (properties.hasOwnProperty(property)) {
const propertyValue = properties[property]; const propertyValue = properties[property];
// This should be ran after the original constructor has finished.
console.log(type);
if (property === Serializable.childrenMap[type].childrenListName) { if (property === Serializable.childrenMap[type].childrenListName) {
// This should be ran after the original constructor has finished.
new Promise(r => r()).then(() => { new Promise(r => r()).then(() => {
for (let child of propertyValue) { for (let child of propertyValue) {
new Serializable.childrenMap[type].childrenConstructor(this, child); new Serializable.childrenMap[type].childrenConstructor(
this,
child,
Serializable.childrenMap[type].childrenType
);
} }
}); });
} else { } else {
this[property] = properties[property]; this[property] = properties[property];
} }
if (!Serializable.propertyList[type].includes(property)) { if (!Serializable.propertyList[compiledType].includes(property)) {
Serializable.propertyList[type].push(property); Serializable.propertyList[compiledType].push(property);
} }
} }
} }

View file

@ -9,6 +9,8 @@ import { IColor } from '../interfaces/color';
export type ColoredBlock = Block & { color: IColor }; export type ColoredBlock = Block & { color: IColor };
export class Tower extends Serializable implements ITower { export class Tower extends Serializable implements ITower {
protected type = 'Tower';
tags: string[]; tags: string[];
name: string; name: string;
@ -21,7 +23,7 @@ export class Tower extends Serializable implements ITower {
readonly baseColor: IColor; readonly baseColor: IColor;
constructor(parent: Node, props: ITower) { constructor(parent: Node, props: ITower) {
super(parent, props); super(parent, props, 'Tower');
this.onAfterClone(); this.onAfterClone();
} }

View file

@ -30,15 +30,18 @@ export class DataService extends Root<Page> {
Serializable.childrenMap = { Serializable.childrenMap = {
Page: { Page: {
childrenListName: 'towers', childrenListName: 'towers',
childrenConstructor: Tower childrenConstructor: Tower,
childrenType: 'Tower'
}, },
Tower: { Tower: {
childrenListName: 'blocks', childrenListName: 'blocks',
childrenConstructor: Block childrenConstructor: Block,
childrenType: 'Block'
}, },
Block: { Block: {
childrenListName: null, childrenListName: null,
childrenConstructor: null childrenConstructor: null,
childrenType: null
} }
}; };

View file

@ -114,7 +114,7 @@ export class StoreService<T> {
return this.storedData; return this.storedData;
} }
async save(data: T) { async save(data: T): Promise<void> {
this.storedData = data; this.storedData = data;
const stringified = JSON.stringify(this.storedData, null, 2); const stringified = JSON.stringify(this.storedData, null, 2);
console.log('save'); console.log('save');