Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复事件绑定不稳定引用引发的内存泄漏问题 #2350

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions frontend/src/app/models/ChartSelectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export class ChartSelectionManager {
private _selectedItems: Array<SelectedItem> = [];
private _multipleSelect: boolean = false;
private _clickCallbacks: Function[] = [];
private windowKeyEventHandlerRef: (this: Window, ev: KeyboardEvent) => any = this.windowKeyEventHandler.bind(this)
private zRenderMouseEventHandlerRef: (this: Window, ev: KeyboardEvent) => any = this.zRenderMouseEventHandler.bind(this)


constructor(events?: ChartMouseEvent[]) {
this._clickCallbacks =
Expand All @@ -46,24 +49,24 @@ export class ChartSelectionManager {
}

public attachWindowListeners(window: Window) {
window?.addEventListener('keydown', this.windowKeyEventHandler.bind(this));
window?.addEventListener('keyup', this.windowKeyEventHandler.bind(this));
window?.addEventListener('keydown', this.windowKeyEventHandlerRef);
window?.addEventListener('keyup', this.windowKeyEventHandlerRef);
}

public removeWindowListeners(window: Window) {
window?.removeEventListener(
'keydown',
this.windowKeyEventHandler.bind(this),
this.windowKeyEventHandlerRef,
);
window?.removeEventListener('keyup', this.windowKeyEventHandler.bind(this));
window?.removeEventListener('keyup', this.windowKeyEventHandlerRef);
}

public attachZRenderListeners(chart: EChartsType) {
chart?.getZr().on('click', this.zRenderMouseEventHandler.bind(this));
chart?.getZr().on('click', this.zRenderMouseEventHandlerRef);
}

public removeZRenderListeners(chart: EChartsType) {
chart?.getZr().off('click', this.zRenderMouseEventHandler.bind(this));
chart?.getZr().off('click', this.zRenderMouseEventHandlerRef);
}

public attachEChartsListeners(chart: EChartsType) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/pages/DashBoardPage/utils/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ export const getWidgetMap = (
) {
content.config.controllerDate.startTime.exactValue =
_value?.[0];
content.config.controllerDate.endTime.exactValue = _value?.[0];
content.config.controllerDate.endTime.exactValue = _value?.[1] ?? _value?.[0];
}
break;

Expand All @@ -600,7 +600,7 @@ export const getWidgetMap = (
...(content.config.controllerDate as any),
startTime: {
relativeOrExact: TimeFilterValueCategory.Exact,
exactValue: formatTime(_value as any, TIME_FORMATTER),
exactValue: formatTime(_value?.[0] as any, TIME_FORMATTER),
},
};
break;
Expand Down