Skip to content

Commit

Permalink
feat: improve almostTheSame comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-Beast committed Sep 7, 2024
1 parent de2ff22 commit 89b6acc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
19 changes: 10 additions & 9 deletions src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,18 @@ export class Block {
return false;
}

if (this.children?.length !== other.children?.length) {
return false;
}

if (!this.children) return false;
if (this.children?.length) {
if (!other.children?.length) return false;
if (this.children.length !== other.children.length) return false;

for (let i = 0; i < this.children.length; ++i) {
const child = getValue(this.children[i]);
const otherChild = getValue(other.children![i]);
for (let i = 0; i < this.children.length; ++i) {
const child = getValue(this.children[i]);
const otherChild = getValue(other.children![i]);

if (!child.almostTheSame(otherChild)) return false;
if (!child.almostTheSame(otherChild)) return false;
}
} else if (other.children?.length) {
return false;
}

return true;
Expand Down
9 changes: 0 additions & 9 deletions src/style_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,6 @@ export class StyleBlock extends Block {
this.changed = true;
}

almostTheSame(other: Block): boolean {
if (other instanceof StyleBlock) {
if (this.style !== other?.style) return false;
else if (this.content !== other.content) return false;
}

return super.almostTheSame(other);
}

forceUpdate(): void {
this.updateLines();
super.forceUpdate();
Expand Down
6 changes: 1 addition & 5 deletions src/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ export type Dynamic = (size: number) => number;
export type NoAutoUnit = Percent | Cell | Dynamic;
export type Unit = NoAutoUnit | Auto;

export function normalizeUnit(
value: NoAutoUnit,
size: number,
usedSize?: number,
): number {
export function normalizeUnit(value: NoAutoUnit, size: number, usedSize?: number): number {
if (typeof value === "number") {
return value;
} else if (typeof value === "function") {
Expand Down

0 comments on commit 89b6acc

Please sign in to comment.