Skip to content

Commit

Permalink
refactor: change method visibility from public to private
Browse files Browse the repository at this point in the history
  • Loading branch information
luolonghao committed Oct 25, 2024
1 parent 5ffec64 commit 99be879
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,17 @@ export class Editor {
});
}

// Removes all unused box instances.
private removeBoxGarbage() {
const instanceMap = getInstanceMap(this.container.id);
for (const box of instanceMap.values()) {
if (!box.node.get(0).isConnected) {
box.unmount();
instanceMap.delete(box.node.id);
}
}
}

// Binds events for history.
private bindHistoryEvents(): void {
const executeCommonMethods = (value: string) => {
Expand Down Expand Up @@ -503,17 +514,6 @@ export class Editor {
}
}

// Removes all unused box instances.
public removeBoxGarbage() {
const instanceMap = getInstanceMap(this.container.id);
for (const box of instanceMap.values()) {
if (!box.node.get(0).isConnected) {
box.unmount();
instanceMap.delete(box.node.id);
}
}
}

// Renders all boxes that haven't been rendered yet.
public renderBoxes(): void {
this.removeBoxGarbage();
Expand Down
2 changes: 1 addition & 1 deletion src/ui/floating-toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class FloatingToolbar extends Toolbar {

private resizeListener = () => this.updatePosition();

public updatePosition(): void {
private updatePosition(): void {
const visible = isVisible(this.range);
if (!visible.top) {
this.container.css('visibility', 'hidden');
Expand Down
4 changes: 2 additions & 2 deletions tests/editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,15 @@ describe('editor', () => {
editor.unmount();
});

it('method: removeBoxGarbage', () => {
it('method: renderBoxes', () => {
const editor = new Editor({
root: rootNode,
value: '<lake-box type="block" name="hr" focus="end"></lake-box><lake-box type="block" name="hr"></lake-box>',
});
editor.render();
editor.container.find('lake-box').eq(1).remove();
expect(getInstanceMap(editor.container.id).size).to.equal(2);
editor.removeBoxGarbage();
editor.renderBoxes();
expect(getInstanceMap(editor.container.id).size).to.equal(1);
editor.unmount();
});
Expand Down

0 comments on commit 99be879

Please sign in to comment.