|
1 | 1 | import { batchFlush, batchStart, type BatchTask, batchTasks } from "../batch"; |
2 | 2 | import { type EventObject, on, type RemoveListener, send, size } from "../event"; |
| 3 | +import { type ReadableProvider, type OwnedWritable, type Readable } from "../interface"; |
3 | 4 | import { writable } from "../readable"; |
4 | | -import { type ReadableProvider, type OwnedWritable, type Readable } from "../typings"; |
5 | 5 | import { strictEqual } from "../utils"; |
6 | 6 | import { onDisposeValue, type OnDisposeValue } from "./utils"; |
7 | 7 |
|
@@ -37,6 +37,7 @@ export class OwnedReactiveMap<K, V> extends Map<K, V> implements ReadableProvide |
37 | 37 | batchTask_: () => { |
38 | 38 | if (this._onChanged_ && size(this._onChanged_)) { |
39 | 39 | const { upsert_, delete_ } = this._onChanged_; |
| 40 | + /** c8 ignore else -- @preserve */ |
40 | 41 | if (upsert_.size > 0 || delete_.size > 0) { |
41 | 42 | const changedData = { |
42 | 43 | upsert: [...upsert_], |
@@ -141,17 +142,17 @@ export class OwnedReactiveMap<K, V> extends Map<K, V> implements ReadableProvide |
141 | 142 | public override clear(): void { |
142 | 143 | if (this.size) { |
143 | 144 | const isBatchTop = batchStart(); |
144 | | - if (this.onDisposeValue_ || this._onChanged_) { |
145 | | - for (const [key, value] of this) { |
146 | | - if (this.onDisposeValue_) { |
147 | | - this.onDisposeValue_.delete_.add(value); |
148 | | - batchTasks.add(this.onDisposeValue_); |
149 | | - } |
150 | | - if (this._onChanged_) { |
151 | | - this._onChanged_.delete_.add(key); |
152 | | - this._onChanged_.upsert_.delete(key); |
153 | | - batchTasks.add(this._onChanged_); |
154 | | - } |
| 145 | + if (this.onDisposeValue_) { |
| 146 | + for (const value of this.values()) { |
| 147 | + this.onDisposeValue_.delete_.add(value); |
| 148 | + batchTasks.add(this.onDisposeValue_); |
| 149 | + } |
| 150 | + } |
| 151 | + if (this._onChanged_) { |
| 152 | + for (const key of this.keys()) { |
| 153 | + this._onChanged_.delete_.add(key); |
| 154 | + this._onChanged_.upsert_.delete(key); |
| 155 | + batchTasks.add(this._onChanged_); |
155 | 156 | } |
156 | 157 | } |
157 | 158 | super.clear(); |
|
0 commit comments