147
148
private onDidChangeItemsExternal(e: IStorageItemsChangeEvent): void {
149
>
this._onDidChangeStorage.pause();
storage.ts
150
>
151
>
try {
152
>
// items that change external require us to update our
153
>
// caches with the values. we just accept the value and
154
>
// emit an event if there is a change.
155
>
156
>
e.changed?.forEach((value, key) => this.acceptExternal(key, value));
157
>
e.deleted?.forEach(key => this.acceptExternal(key, undefined));
158
>
159
>
} finally {
160
>
this._onDidChangeStorage.resume();
161
>
}
162
>
}
163
164
private acceptExternal(key: string, value: string | undefined): void {
165
>
if (this.state === StorageState.Closed) {
storage.ts
166
return; // Return early if we are already closed
167
}
169
>
let changed = false;
170
>
171
>
// Item got removed, check for deletion
172
>
if (isUndefinedOrNull(value)) {
173
changed = this.cache.delete(key);
174
}
176
>
// Item got updated, check for change
177
>
else {
178
>
const currentValue = this.cache.get(key);
179
>
if (currentValue !== value) {
180
this.cache.set(key, value);
181
changed = true;
182
}
184
>
185
>
// Signal to outside listeners
186
>
if (changed) {
187
this._onDidChangeStorage.fire({ key, external: true });
188
}
190
191
get items(): Map<string, string> {