By checking which selectors are affected by a MutationObserver trigger and only calling the listeners of those, the performance should be MUCH better on more complex pages with frequent DOM changes.
To achieve this, for each added/removed/edited node and for each registered selector, check if the element itself matches the selector (via changedElement.matches(selector)), the selector is a child of the element (via changedElement.querySelector(selector)) or descend up the parents of the element.
This whole functionality should be toggleable with a constructor option.
By checking which selectors are affected by a MutationObserver trigger and only calling the listeners of those, the performance should be MUCH better on more complex pages with frequent DOM changes.
To achieve this, for each added/removed/edited node and for each registered selector, check if the element itself matches the selector (via
changedElement.matches(selector)), the selector is a child of the element (viachangedElement.querySelector(selector)) or descend up the parents of the element.This whole functionality should be toggleable with a constructor option.