Skip to content

Commit

Permalink
fix(geometry): geometry.clear() 以及 destroy() 时要清空、销毁内部变量
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ authored and hustcc committed Apr 9, 2020
1 parent 21e8189 commit c89ff97
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/geometry/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ export default class Geometry extends Base {
* @override
*/
public clear() {
const { container, geometryLabel } = this;
const { container, geometryLabel, offscreenGroup } = this;
if (container) {
container.clear();
}
Expand All @@ -891,12 +891,18 @@ export default class Geometry extends Base {
geometryLabel.clear();
}

if (offscreenGroup) {
offscreenGroup.clear();
}

// 属性恢复至出厂状态
this.scaleDefs = undefined;
this.attributes = {};
this.scales = {};
this.elementsMap = {};
this.lastElementsMap = {};
this.elements = [];
this.adjusts = {};
this.dataArray = null;
this.beforeMappingData = null;
this.lastAttributeOption = undefined;
Expand All @@ -923,6 +929,8 @@ export default class Geometry extends Base {
this.geometryLabel = null;
}
this.theme = undefined;
this.shapeFactory = undefined;

super.destroy();
}

Expand Down Expand Up @@ -1223,7 +1231,7 @@ export default class Geometry extends Base {
// 因为这里缓存了 shapeFactory,但是外部可能会变更 coordinate,导致无法重新设置到 shapeFactory 中
this.shapeFactory.coordinate = this.coordinate;
// theme 原因同上
this.shapeFactory.theme = get(this.theme, ['geometries', shapeType], {});
this.shapeFactory.theme = this.theme.geometries[shapeType] || {};

return this.shapeFactory;
}
Expand Down

0 comments on commit c89ff97

Please sign in to comment.