* Subscribes an observer to the mutation and stops its garbage collection. * @internal * @param observer - The observer to add. Adding an observer that is already subscribed does * nothing.
(observer: MutationObserver<any, any, any, any>)
| 195 | * nothing. |
| 196 | */ |
| 197 | addObserver(observer: MutationObserver<any, any, any, any>): void { |
| 198 | if (!this.#observers.includes(observer)) { |
| 199 | this.#observers.push(observer) |
| 200 | |
| 201 | // Stop the mutation from being garbage collected |
| 202 | this.clearGcTimeout() |
| 203 | |
| 204 | this.#mutationCache.notify({ |
| 205 | type: 'observerAdded', |
| 206 | mutation: this, |
| 207 | observer, |
| 208 | }) |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Unsubscribes an observer from the mutation. |