* Removes a mutation from the cache and clears its garbage collection timer. * @internal * @param mutation - The mutation to remove, also from its scope's queue.
(mutation: Mutation<any, any, any, any>)
| 184 | * @param mutation - The mutation to remove, also from its scope's queue. |
| 185 | */ |
| 186 | remove(mutation: Mutation<any, any, any, any>): void { |
| 187 | if (this.#mutations.delete(mutation)) { |
| 188 | mutation.destroy() |
| 189 | const scope = scopeFor(mutation) |
| 190 | if (typeof scope === 'string') { |
| 191 | const scopedMutations = this.#scopes.get(scope) |
| 192 | if (scopedMutations) { |
| 193 | if (scopedMutations.length > 1) { |
| 194 | const index = scopedMutations.indexOf(mutation) |
| 195 | if (index !== -1) { |
| 196 | scopedMutations.splice(index, 1) |
| 197 | } |
| 198 | } else if (scopedMutations[0] === mutation) { |
| 199 | this.#scopes.delete(scope) |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | // Currently we notify the removal even if the mutation was already removed. |
| 206 | // Consider making this an error or not notifying of the removal depending on the desired semantics. |
| 207 | this.notify({ type: 'removed', mutation }) |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Checks whether this cache still holds the given mutation. |