Skip to content

Commit

Permalink
fix: memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-Beast committed Sep 7, 2024
1 parent 4af3f6e commit 287aa81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,16 @@ export class Block {
}
}

addChild(blockSignal: MaybeSignal<Block>, position?: number): void {
const block = getValue(blockSignal);
block.parent = this;
addChild(block: MaybeSignal<Block>, position?: number): void {
const blockValue = getValue(block);
blockValue.parent = this;
this.children ??= [];
if (typeof position === "number") {
this.children.splice(position, 0, blockSignal);
this.children.splice(position, 0, block);
} else {
this.children.push(blockSignal);
this.children.push(block);
}
block.mount();
blockValue.mount();
this.changed = true;
}

Expand All @@ -216,12 +216,12 @@ export class Block {
this.changed = true;
}

removeChild(blockSignal: MaybeSignal<Block>): void {
const block = getValue(blockSignal);
block.parent = undefined;
block.unmount();
removeChild(block: MaybeSignal<Block>): void {
const blockValue = getValue(block);
blockValue.parent = undefined;
blockValue.unmount();

const index = this.children?.findIndex((value) => value === block || value === blockSignal);
const index = this.children?.findIndex((value) => value === blockValue || value === block);
if (typeof index !== "number" || index === -1) return;

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

static i = 0;
almostTheSame(other: Block): boolean {
if (other instanceof StyleBlock) {
if (this.style !== other.style) return false;
}

return super.almostTheSame(other);
}

forceUpdate(): void {
this.updateLines();
super.forceUpdate();
Expand Down

0 comments on commit 287aa81

Please sign in to comment.