Skip to content

Commit

Permalink
feat: update event listening
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtengjin committed Feb 1, 2024
1 parent d5d5665 commit fc6f21e
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/lib/components/topology/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ class Topology extends React.Component<ITopologyProps, ITopologyState> {
} = this.props;
this.editLine = _.throttle(this.editLine, this.hoverThreshold);
if (!readOnly) {
this.initDomEvents();
this.initKeydownEvent();
}
this.initWheelEvent();

// $wrapper 赋值
// this.$wrapper = document.querySelector('.minimap-container-scroll');
Expand Down Expand Up @@ -264,10 +265,10 @@ class Topology extends React.Component<ITopologyProps, ITopologyState> {
this.renderDomMap(nextProps);
this.shouldAutoLayout = shouldAutoLayout(nextProps.data.nodes);
if (readOnly && !nextReadOnly) {
this.initDomEvents();
this.initKeydownEvent();
}
if (!readOnly && nextReadOnly) {
this.removeDomEvents();
this.removeKeydownEvent();
}
}

Expand All @@ -285,7 +286,8 @@ class Topology extends React.Component<ITopologyProps, ITopologyState> {
this.editLine.cancel();
}

this.removeDomEvents();
this.removeKeydownEvent();
this.removeWheelEvent();
}

onChange = (data: ITopologyData, type: ChangeType) => {
Expand Down Expand Up @@ -532,15 +534,21 @@ class Topology extends React.Component<ITopologyProps, ITopologyState> {
}
}

initDomEvents = () => {
initKeydownEvent = () => {
window.addEventListener("keydown", this.handleKeydown);
this.$wrapper.addEventListener("wheel", this.listenerWheel);
};
}

removeDomEvents = () => {
removeKeydownEvent = () => {
window.removeEventListener("keydown", this.handleKeydown);
}

initWheelEvent = () => {
this.$wrapper.addEventListener("wheel", this.listenerWheel);
}

removeWheelEvent = () => {
this.$wrapper.removeEventListener("wheel", this.listenerWheel);
};
}

getBoundary = (elements: Element[]) => {
let minX = Infinity;
Expand Down

0 comments on commit fc6f21e

Please sign in to comment.