Skip to content

Commit

Permalink
fix: dispose model update listeners (#8857)
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlewind authored Dec 4, 2024
1 parent 9cd3d8c commit 0a89339
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,16 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
}
}

this.model.propsUpdated.on(({ key }) => {
if (key === 'pageId' || key === 'style') {
this._load().catch(e => {
console.error(e);
this.isError = true;
});
}
});
this.disposables.add(
this.model.propsUpdated.on(({ key }) => {
if (key === 'pageId' || key === 'style') {
this._load().catch(e => {
console.error(e);
this.isError = true;
});
}
})
);
}

override disconnectedCallback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,16 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce

this.contentEditable = 'false';

this.model.propsUpdated.on(({ key }) => {
if (key === 'pageId' || key === 'style') {
this._load().catch(e => {
console.error(e);
this._error = true;
});
}
});
this.disposables.add(
this.model.propsUpdated.on(({ key }) => {
if (key === 'pageId' || key === 'style') {
this._load().catch(e => {
console.error(e);
this._error = true;
});
}
})
);

this._setDocUpdatedAt();
this.disposables.add(
Expand Down
12 changes: 7 additions & 5 deletions packages/blocks/src/image-block/image-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ export class ImageBlockComponent extends CaptionedBlockComponent<

this.refreshData();
this.contentEditable = 'false';
this.model.propsUpdated.on(({ key }) => {
if (key === 'sourceId') {
this.refreshData();
}
});
this._disposables.add(
this.model.propsUpdated.on(({ key }) => {
if (key === 'sourceId') {
this.refreshData();
}
})
);
}

override disconnectedCallback() {
Expand Down
12 changes: 7 additions & 5 deletions packages/blocks/src/image-block/image-edgeless-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ export class ImageEdgelessBlockComponent extends GfxBlockComponent<

this.refreshData();
this.contentEditable = 'false';
this.model.propsUpdated.on(({ key }) => {
if (key === 'sourceId') {
this.refreshData();
}
});
this.disposables.add(
this.model.propsUpdated.on(({ key }) => {
if (key === 'sourceId') {
this.refreshData();
}
})
);
}

override disconnectedCallback() {
Expand Down
9 changes: 5 additions & 4 deletions packages/docs/guide/block-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ class MyBlockView extends BlockComponent<MyBlockModel> {

override connectedCallback() {
super.connectedCallback();

this.model.propsUpdated.on(() => {
this._yen = `${this.model.count * 100`;
});
this.disposables.add(
this.model.propsUpdated.on(() => {
this._yen = `${this.model.count * 100`;
})
);
}

override render() {
Expand Down

0 comments on commit 0a89339

Please sign in to comment.