From 61d00e03a3cfb85db97d9c1cceabf61871de93c8 Mon Sep 17 00:00:00 2001 From: pubuzhixing8 Date: Tue, 30 Apr 2024 16:48:54 +0800 Subject: [PATCH] refactor(core): remove get component bridge officially (#863) --- .changeset/rare-onions-collect.md | 9 +++++++++ packages/core/src/core/element/plugin-element.ts | 8 -------- packages/core/src/interfaces/element.ts | 4 ---- 3 files changed, 9 insertions(+), 12 deletions(-) create mode 100644 .changeset/rare-onions-collect.md diff --git a/.changeset/rare-onions-collect.md b/.changeset/rare-onions-collect.md new file mode 100644 index 000000000..ba1467cb3 --- /dev/null +++ b/.changeset/rare-onions-collect.md @@ -0,0 +1,9 @@ +--- +'@plait/core': minor +--- + +remove get component bridge officially 🎉🎉🎉 + +- remove ELEMENT_TO_COMPONENT + +- remove getComponent method diff --git a/packages/core/src/core/element/plugin-element.ts b/packages/core/src/core/element/plugin-element.ts index ebedecf7f..e69135617 100644 --- a/packages/core/src/core/element/plugin-element.ts +++ b/packages/core/src/core/element/plugin-element.ts @@ -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(); @@ -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); } @@ -169,5 +163,3 @@ export abstract class PlaitPluginElementComponent< this.getContainerG().remove(); } } - -export const ELEMENT_TO_COMPONENT = new WeakMap(); diff --git a/packages/core/src/interfaces/element.ts b/packages/core/src/interfaces/element.ts index 680c8299a..cbf2921b0 100644 --- a/packages/core/src/interfaces/element.ts +++ b/packages/core/src/interfaces/element.ts @@ -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'; @@ -22,9 +21,6 @@ export const PlaitElement = { return false; } }, - getComponent(value: PlaitElement) { - return ELEMENT_TO_COMPONENT.get(value) as PlaitPluginElementComponent; - }, getElementRef(value: PlaitElement) { return ELEMENT_TO_REF.get(value) as T; },