Skip to content

Commit

Permalink
refactor(core): remove get component bridge officially (#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
pubuzhixing8 authored Apr 30, 2024
1 parent a1e2b94 commit 61d00e0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
9 changes: 9 additions & 0 deletions .changeset/rare-onions-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@plait/core': minor
---

remove get component bridge officially 🎉🎉🎉

- remove ELEMENT_TO_COMPONENT

- remove getComponent method
8 changes: 0 additions & 8 deletions packages/core/src/core/element/plugin-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ export abstract class PlaitPluginElementComponent<
}
const previousContext = this._context;
this._context = value;
if (this.element) {
ELEMENT_TO_COMPONENT.set(this.element, this);
}
if (this.initialized) {
const elementG = this.getElementG();
const containerG = this.getContainerG();
Expand Down Expand Up @@ -153,9 +150,6 @@ export abstract class PlaitPluginElementComponent<
}

ngOnDestroy(): void {
if (ELEMENT_TO_COMPONENT.get(this.element) === this) {
ELEMENT_TO_COMPONENT.delete(this.element);
}
if (NODE_TO_G.get(this.element) === this._g) {
NODE_TO_G.delete(this.element);
}
Expand All @@ -169,5 +163,3 @@ export abstract class PlaitPluginElementComponent<
this.getContainerG().remove();
}
}

export const ELEMENT_TO_COMPONENT = new WeakMap<PlaitElement, PlaitPluginElementComponent>();
4 changes: 0 additions & 4 deletions packages/core/src/interfaces/element.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ELEMENT_TO_COMPONENT, PlaitPluginElementComponent } from '../core/element/plugin-element';
import { ELEMENT_TO_REF, NODE_TO_CONTAINER_G, NODE_TO_G, NODE_TO_PARENT } from '../utils';
import { PlaitBoard } from './board';
import { Point } from './point';
Expand All @@ -22,9 +21,6 @@ export const PlaitElement = {
return false;
}
},
getComponent(value: PlaitElement) {
return ELEMENT_TO_COMPONENT.get(value) as PlaitPluginElementComponent;
},
getElementRef<T extends PlaitElementRef = PlaitElementRef>(value: PlaitElement) {
return ELEMENT_TO_REF.get(value) as T;
},
Expand Down

0 comments on commit 61d00e0

Please sign in to comment.