Adrià Vilanova MartÃnez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 1 | export 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 | |
| 16 | export interface NodeMutation { |
| 17 | /** |
| 18 | * Node being mutated. |
| 19 | */ |
| 20 | node: Node; |
| 21 | /** |
| 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 | |
| 32 | export 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 | } |