blob: bf57020870ddd4d60a1d8c689a4b09cc60c3a11b [file] [log] [blame]
Adrià Vilanova Martínezf92172f2024-10-19 15:55:15 +02001import {
2 NodeMutation,
3 NodeMutationType,
4 NodeWatcherHandler,
5} from '../../../../presentation/nodeWatcher/NodeWatcherHandler';
6
7export default abstract class CssSelectorNodeWatcherHandler
8 implements NodeWatcherHandler
9{
10 readonly mutationTypesProcessed: NodeMutationType[] = [
11 NodeMutationType.InitialDiscovery,
12 NodeMutationType.NewNode,
13 ];
14
15 abstract readonly cssSelector: string;
16
17 nodeFilter(nodeMutation: NodeMutation): boolean {
18 if (
19 !this.mutationTypesProcessed.includes(nodeMutation.type) ||
20 !(nodeMutation.node instanceof Element)
21 ) {
22 return false;
23 }
24 return nodeMutation.node.matches(this.cssSelector);
25 }
26
27 get initialDiscoverySelector() {
28 return this.cssSelector;
29 }
30
31 abstract onMutatedNode(nodeMutation: NodeMutation): void;
32}