diff --git a/src/common/utils/extended-map.ts b/src/common/utils/extended-map.ts index c8b7ff4c65..c759fa3459 100644 --- a/src/common/utils/extended-map.ts +++ b/src/common/utils/extended-map.ts @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { action, IEnhancer, IObservableMapInitialValues, ObservableMap } from "mobx"; +import { action, ObservableMap } from "mobx"; export class ExtendedMap extends Map { static new(entries?: readonly (readonly [K, V])[] | null): ExtendedMap { @@ -67,34 +67,12 @@ export class ExtendedMap extends Map { } export class ExtendedObservableMap extends ObservableMap { - constructor(protected getDefault: () => V, initialData?: IObservableMapInitialValues, enhancer?: IEnhancer, name?: string) { - super(initialData, enhancer, name); - } - @action - getOrInsert(key: K, val: V): V { - if (this.has(key)) { - return this.get(key); - } - - return this.set(key, val).get(key); - } - - @action - getOrInsertWith(key: K, getVal: () => V): V { + getOrInsert(key: K, getVal: () => V): V { if (this.has(key)) { return this.get(key); } return this.set(key, getVal()).get(key); } - - @action - getOrDefault(key: K): V { - if (this.has(key)) { - return this.get(key); - } - - return this.set(key, this.getDefault()).get(key); - } } diff --git a/src/main/catalog-sources/kubeconfig-sync.ts b/src/main/catalog-sources/kubeconfig-sync.ts index c8029a421f..0f481741d6 100644 --- a/src/main/catalog-sources/kubeconfig-sync.ts +++ b/src/main/catalog-sources/kubeconfig-sync.ts @@ -255,17 +255,17 @@ async function watchFileChanges(filePath: string): Promise<[IComputedValue>(observable.map); + const rootSource = new ExtendedObservableMap>(); const derivedSource = computed(() => Array.from(iter.flatMap(rootSource.values(), from => iter.map(from.values(), child => child[1])))); const stoppers = new Map(); watcher .on("change", (childFilePath) => { stoppers.get(childFilePath)(); - stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrDefault(childFilePath))); + stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrInsert(childFilePath, observable.map))); }) .on("add", (childFilePath) => { - stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrDefault(childFilePath))); + stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrInsert(childFilePath, observable.map))); }) .on("unlink", (childFilePath) => { stoppers.get(childFilePath)();