Adrià Vilanova Martínez | f92172f | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 1 | import { |
| 2 | NodeMutation, |
| 3 | NodeMutationType, |
| 4 | NodeWatcherHandler, |
| 5 | } from '../../../../presentation/nodeWatcher/NodeWatcherHandler'; |
| 6 | |
| 7 | export 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 | |
Adrià Vilanova Martínez | 3c13a76 | 2024-11-09 23:03:32 +0100 | [diff] [blame] | 31 | abstract onMutatedNode(nodeMutation: NodeMutation<HTMLElement>): void; |
Adrià Vilanova Martínez | f92172f | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 32 | } |