Skip to content

Commit

Permalink
Use MutationObserver instead of Mutation Events
Browse files Browse the repository at this point in the history
Mutation Events have been deprecated in favour of MutationObserver.
This change prevents deprecation warnings from showing in browser
dev consoles.
  • Loading branch information
mikelkew committed Aug 19, 2020
1 parent e1ed9e6 commit ace938e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/web_console/templates/console.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,14 @@ REPLConsole.prototype.install = function(container) {
}
}

var observer = new MutationObserver(function(mutationsList) {
for (let mutation of mutationsList) {
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
shiftConsoleActions();
}
}
});

// Initialize
this.container = container;
this.outer = consoleOuter;
Expand All @@ -427,7 +435,7 @@ REPLConsole.prototype.install = function(container) {

findChild(container, 'resizer').addEventListener('mousedown', resizeContainer);
findChild(consoleActions, 'close-button').addEventListener('click', closeContainer);
consoleOuter.addEventListener('DOMNodeInserted', shiftConsoleActions);
observer.observe(consoleOuter, { childList: true, subtree: true });

REPLConsole.currentSession = this;
};
Expand Down

0 comments on commit ace938e

Please sign in to comment.