| 135 | } |
| 136 | |
| 137 | remove(mutation: Mutation<any, any, any, any>): void { |
| 138 | if (this.#mutations.delete(mutation)) { |
| 139 | const scope = scopeFor(mutation) |
| 140 | if (typeof scope === 'string') { |
| 141 | const scopedMutations = this.#scopes.get(scope) |
| 142 | if (scopedMutations) { |
| 143 | if (scopedMutations.length > 1) { |
| 144 | const index = scopedMutations.indexOf(mutation) |
| 145 | if (index !== -1) { |
| 146 | scopedMutations.splice(index, 1) |
| 147 | } |
| 148 | } else if (scopedMutations[0] === mutation) { |
| 149 | this.#scopes.delete(scope) |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | // Currently we notify the removal even if the mutation was already removed. |
| 156 | // Consider making this an error or not notifying of the removal depending on the desired semantics. |
| 157 | this.notify({ type: 'removed', mutation }) |
| 158 | } |
| 159 | |
| 160 | canRun(mutation: Mutation<any, any, any, any>): boolean { |
| 161 | const scope = scopeFor(mutation) |