bug: remove unwanted code

This commit is contained in:
mathuo 2021-04-10 22:03:14 +01:00
parent 92ae705dfb
commit 46fa98fd8c

View File

@ -228,10 +228,7 @@ const serializeBranchNode = <T extends IGridView>(
data: node.children.map((c) => data: node.children.map((c) =>
serializeBranchNode(c, orthogonal(orientation)) serializeBranchNode(c, orthogonal(orientation))
), ),
size: size,
orientation === Orientation.HORIZONTAL
? node.box.width
: node.box.height,
}; };
}; };
@ -258,56 +255,6 @@ export interface INodeDescriptor {
export interface IViewDeserializer { export interface IViewDeserializer {
fromJSON: (data: ISerializedLeafNode) => IGridView; fromJSON: (data: ISerializedLeafNode) => IGridView;
} }
function getDimensions<T>(
node: SerializedGridObject<T>,
orientation: Orientation
): { width?: number; height?: number } {
if (node.type === 'branch') {
const childrenDimensions = (node.data as SerializedGridObject<T>[]).map(
(c) => getDimensions(c, orthogonal(orientation))
);
if (orientation === Orientation.VERTICAL) {
const width =
node.size ||
(childrenDimensions.length === 0
? undefined
: Math.max(...childrenDimensions.map((d) => d.width || 0)));
const height =
childrenDimensions.length === 0
? undefined
: childrenDimensions.reduce(
(r, d) => r + (d.height || 0),
0
);
return { width, height };
} else {
const width =
childrenDimensions.length === 0
? undefined
: childrenDimensions.reduce(
(r, d) => r + (d.width || 0),
0
);
const height =
node.size ||
(childrenDimensions.length === 0
? undefined
: Math.max(
...childrenDimensions.map((d) => d.height || 0)
));
return { width, height };
}
} else {
const width =
orientation === Orientation.VERTICAL ? node.size : undefined;
const height =
orientation === Orientation.VERTICAL ? undefined : node.size;
return { width, height };
}
}
export class Gridview implements IDisposable { export class Gridview implements IDisposable {
private _root: BranchNode | undefined; private _root: BranchNode | undefined;
public readonly element: HTMLElement; public readonly element: HTMLElement;
@ -318,15 +265,6 @@ export class Gridview implements IDisposable {
public serialize() { public serialize() {
const root = serializeBranchNode(this.getView(), this.orientation); const root = serializeBranchNode(this.getView(), this.orientation);
const { width, height } = getDimensions(root, this.orientation);
console.log('test');
if (width !== this.width) {
console.log(`width ${width} !== this.width ${this.width}`);
}
if (height !== this.height) {
console.log(`height ${height} !== this.height ${this.height}`);
}
return { return {
root, root,
@ -354,10 +292,7 @@ export class Gridview implements IDisposable {
public deserialize(json: any, deserializer: IViewDeserializer) { public deserialize(json: any, deserializer: IViewDeserializer) {
const orientation = json.orientation; const orientation = json.orientation;
const height = const height = json.height;
orientation === Orientation.VERTICAL ? json.height : json.width;
// this.orientation = orientation;
this._deserialize( this._deserialize(
json.root as ISerializedBranchNode, json.root as ISerializedBranchNode,
orientation, orientation,
@ -374,7 +309,7 @@ export class Gridview implements IDisposable {
): void { ): void {
this.root = this._deserializeNode( this.root = this._deserializeNode(
root, root,
orthogonal(orientation), orientation,
deserializer, deserializer,
orthogonalSize orthogonalSize
) as BranchNode; ) as BranchNode;