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

Replaced DOMNodeRemoved event by MutationObserver #1431

Open
wants to merge 1 commit into
base: main
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
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,18 @@ class GraphQLEditor extends React.PureComponent<Props & ReduxProps> {
private handleHintInformationRender = elem => {
elem.addEventListener('click', this.onClickHintInformation)

let onRemoveFn
elem.addEventListener(
'DOMNodeRemoved',
(onRemoveFn = () => {
elem.removeEventListener('DOMNodeRemoved', onRemoveFn)
elem.removeEventListener('click', this.onClickHintInformation)
}),
)
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.removedNodes.forEach((removedNode) => {
if (removedNode === elem) {
elem.removeEventListener('click', this.onClickHintInformation);
observer.disconnect();
}
});
});
});

observer.observe(elem, { childList: true });
}

private handleResizeStart = downEvent => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,20 @@ export default function onHasCompletion(cm, data, onHintInformationRender) {
// When CodeMirror attempts to remove the hint UI, we detect that it was
// removed from our wrapper and in turn remove the wrapper from the
// original container.
let onRemoveFn
wrapper.addEventListener(
'DOMNodeRemoved',
(onRemoveFn = event => {
if (event.target === hintsUl) {
wrapper.removeEventListener('DOMNodeRemoved', onRemoveFn)
wrapper.parentNode.removeChild(wrapper)
wrapper = null
information = null
onRemoveFn = null
}
}),
)
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.removedNodes.forEach((removedNode) => {
if (removedNode === hintsUl) {
wrapper.parentNode.removeChild(wrapper);
wrapper = null;
information = null;
observer.disconnect();
}
});
});
});

observer.observe(wrapper, { childList: true });
}

// Now that the UI has been set up, add info to information.
Expand Down