We would like to observe changes to the DOM and, for each changed element el
, call one or more functions f1, f2, ..., fn
, passing el
as an argument to each. For each function, if it returns true, add a CSS class C
to el
, and otherwise remove class C
from el
.
Register a mutation observer on the root element of the DOM. The mutation observer is responsible for tracking the "generation" of all elements in the DOM and for marshalling MutationRecord
s to a Web Worker. Specifically:
- For each mutation:
- increment the generation of the mutated element and its ancestors