blob: bf57020870ddd4d60a1d8c689a4b09cc60c3a11b [file] [log] [blame]
import {
NodeMutation,
NodeMutationType,
NodeWatcherHandler,
} from '../../../../presentation/nodeWatcher/NodeWatcherHandler';
export default abstract class CssSelectorNodeWatcherHandler
implements NodeWatcherHandler
{
readonly mutationTypesProcessed: NodeMutationType[] = [
NodeMutationType.InitialDiscovery,
NodeMutationType.NewNode,
];
abstract readonly cssSelector: string;
nodeFilter(nodeMutation: NodeMutation): boolean {
if (
!this.mutationTypesProcessed.includes(nodeMutation.type) ||
!(nodeMutation.node instanceof Element)
) {
return false;
}
return nodeMutation.node.matches(this.cssSelector);
}
get initialDiscoverySelector() {
return this.cssSelector;
}
abstract onMutatedNode(nodeMutation: NodeMutation): void;
}