blob: 67801f46bf8e6d4472c99faee934dc3d6f5fd31d [file] [log] [blame]
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +02001export enum NodeMutationType {
2 /**
3 * The node was found during initial discovery.
4 */
5 InitialDiscovery,
6 /**
7 * The node has been added.
8 */
9 NewNode,
10 /**
11 * The node was removed
12 */
13 RemovedNode,
14}
15
Adrià Vilanova Martínez3c13a762024-11-09 23:03:32 +010016export interface NodeMutation<T extends Node = Node> {
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020017 /**
18 * Node being mutated.
19 */
Adrià Vilanova Martínez3c13a762024-11-09 23:03:32 +010020 node: T;
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020021 /**
22 * Which mutation has occurred to the node.
23 */
24 type: NodeMutationType;
25 /**
26 * MutationRecord from which this node mutation has been extracted. It is null
27 * if the type is {@link NodeMutationType.InitialDiscovery}.
28 */
29 mutationRecord: MutationRecord | null;
30}
31
32export interface NodeWatcherHandler {
33 /**
34 * Only node mutations which pass this filter (it returns true) will be passed
35 * to {@link onMutatedNode}.
36 */
37 nodeFilter: (nodeMutation: NodeMutation) => boolean;
38
39 /**
40 * Optional CSS selector used to discover nodes existing prior to the handler
41 * being established. These matching nodes will be evaluated by
42 * {@link onMutatedNode} if they pass {@link nodeFilter}.
43 *
44 * This is useful when watching an node but it has already been created.
45 */
46 initialDiscoverySelector?: string;
47
48 /**
49 * Function which will be called with each of the filtered node mutations.
50 */
51 onMutatedNode: (nodeMutation: NodeMutation) => void;
52}