Fix bugs
This commit is contained in:
parent
d612678682
commit
3101c973eb
1 changed files with 113 additions and 97 deletions
|
|
@ -4,22 +4,18 @@ import { Block } from './block';
|
|||
import { Serializable } from './serializable';
|
||||
import { hash } from '../utils/hash';
|
||||
import { IColor } from '../interfaces/color';
|
||||
import { InnerNode, InnerNodeState } from '../store/inner-node';
|
||||
import { InnerNodeState } from '../store/inner-node';
|
||||
|
||||
export type ColoredBlock = Block & { color: IColor };
|
||||
|
||||
export interface TowerState extends ITower, InnerNodeState {}
|
||||
export interface TowerState extends ITower, InnerNodeState {
|
||||
blocks: Array<Block>;
|
||||
}
|
||||
|
||||
export class Tower extends Serializable implements ITower, TowerState {
|
||||
tags: string[];
|
||||
readonly name: string;
|
||||
|
||||
get blocks(): Array<Block> {
|
||||
return this.children as Array<Block>;
|
||||
}
|
||||
|
||||
coloredBlocks: Array<ColoredBlock>;
|
||||
|
||||
readonly baseColor: IColor;
|
||||
|
||||
constructor(props: ITower) {
|
||||
|
|
@ -27,6 +23,31 @@ export class Tower extends Serializable implements ITower, TowerState {
|
|||
this.onAfterClone();
|
||||
}
|
||||
|
||||
get blocks(): Array<Block> {
|
||||
return this.children as Array<Block>;
|
||||
}
|
||||
|
||||
changeKeys(props: Partial<TowerState>): this {
|
||||
if (props.hasOwnProperty('blocks')) {
|
||||
props.children = props.blocks;
|
||||
delete props.blocks;
|
||||
}
|
||||
return super.changeKeys<TowerState>(props);
|
||||
}
|
||||
|
||||
addBlock(props: { tag: string; description: string; isDone: boolean }) {
|
||||
this.addChildren([
|
||||
new Block({
|
||||
created: new Date(),
|
||||
...props
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
changeName(name: string) {
|
||||
this.changeKeys({ name });
|
||||
}
|
||||
|
||||
protected onAfterClone() {
|
||||
this.blocks.sort((a, b) => {
|
||||
return a.created.getTime() - b.created.getTime();
|
||||
|
|
@ -45,17 +66,4 @@ export class Tower extends Serializable implements ITower, TowerState {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
addBlock(props: { tag: string; description: string; isDone: boolean }) {
|
||||
this.addChildren([
|
||||
new Block({
|
||||
created: new Date(),
|
||||
...props
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
changeName(name: string) {
|
||||
this.changeKeys<TowerState>({ name });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue