mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
remove ExtendedObservableMap
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
8e6770114b
commit
2c290cb32f
@ -1,11 +1,3 @@
|
|||||||
import {
|
|
||||||
action,
|
|
||||||
IEnhancer,
|
|
||||||
IObservableMapInitialValues,
|
|
||||||
ObservableMap,
|
|
||||||
makeObservable,
|
|
||||||
} from "mobx";
|
|
||||||
|
|
||||||
export class ExtendedMap<K, V> extends Map<K, V> {
|
export class ExtendedMap<K, V> extends Map<K, V> {
|
||||||
constructor(protected getDefault: () => V, entries?: readonly (readonly [K, V])[] | null) {
|
constructor(protected getDefault: () => V, entries?: readonly (readonly [K, V])[] | null) {
|
||||||
super(entries);
|
super(entries);
|
||||||
@ -35,37 +27,3 @@ export class ExtendedMap<K, V> extends Map<K, V> {
|
|||||||
return this.set(key, this.getDefault()).get(key);
|
return this.set(key, this.getDefault()).get(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ExtendedObservableMap<K, V> extends ObservableMap<K, V> {
|
|
||||||
constructor(protected getDefault: () => V, initialData?: IObservableMapInitialValues<K, V>, enhancer?: IEnhancer<V>, name?: string) {
|
|
||||||
super(initialData, enhancer, name);
|
|
||||||
makeObservable(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import { watch } from "chokidar";
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import stream from "stream";
|
import stream from "stream";
|
||||||
import { Disposer, ExtendedObservableMap, iter, Singleton } from "../../common/utils";
|
import { Disposer, iter, Singleton } from "../../common/utils";
|
||||||
import logger from "../logger";
|
import logger from "../logger";
|
||||||
import { KubeConfig } from "@kubernetes/client-node";
|
import { KubeConfig } from "@kubernetes/client-node";
|
||||||
import { loadConfigFromString, splitConfig, validateKubeConfig } from "../../common/kube-helpers";
|
import { loadConfigFromString, splitConfig, validateKubeConfig } from "../../common/kube-helpers";
|
||||||
@ -98,6 +98,7 @@ export class KubeconfigSyncManager extends Singleton {
|
|||||||
logger.info(`${logPrefix} starting sync of file/folder`, { filePath });
|
logger.info(`${logPrefix} starting sync of file/folder`, { filePath });
|
||||||
logger.debug(`${logPrefix} ${this.sources.size} files/folders watched`, { files: Array.from(this.sources.keys()) });
|
logger.debug(`${logPrefix} ${this.sources.size} files/folders watched`, { files: Array.from(this.sources.keys()) });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
logger.warn(`${logPrefix} failed to start watching changes: ${error}`);
|
logger.warn(`${logPrefix} failed to start watching changes: ${error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -241,17 +242,25 @@ async function watchFileChanges(filePath: string): Promise<[IComputedValue<Catal
|
|||||||
depth: stat.isDirectory() ? 0 : 1, // DIRs works with 0 but files need 1 (bug: https://github.com/paulmillr/chokidar/issues/1095)
|
depth: stat.isDirectory() ? 0 : 1, // DIRs works with 0 but files need 1 (bug: https://github.com/paulmillr/chokidar/issues/1095)
|
||||||
disableGlobbing: true,
|
disableGlobbing: true,
|
||||||
});
|
});
|
||||||
const rootSource = new ExtendedObservableMap<string, ObservableMap<string, RootSourceValue>>(observable.map);
|
const rootSource = new ObservableMap<string, ObservableMap<string, RootSourceValue>>();
|
||||||
const derivedSource = computed(() => Array.from(iter.flatMap(rootSource.values(), from => iter.map(from.values(), child => child[1]))));
|
const derivedSource = computed(() => Array.from(iter.flatMap(rootSource.values(), from => iter.map(from.values(), child => child[1]))));
|
||||||
const stoppers = new Map<string, Disposer>();
|
const stoppers = new Map<string, Disposer>();
|
||||||
|
|
||||||
watcher
|
watcher
|
||||||
.on("change", (childFilePath) => {
|
.on("change", (childFilePath) => {
|
||||||
|
if (!rootSource.has(childFilePath)) {
|
||||||
|
rootSource.set(childFilePath, observable.map());
|
||||||
|
}
|
||||||
|
|
||||||
stoppers.get(childFilePath)();
|
stoppers.get(childFilePath)();
|
||||||
stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrDefault(childFilePath)));
|
stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.get(childFilePath)));
|
||||||
})
|
})
|
||||||
.on("add", (childFilePath) => {
|
.on("add", (childFilePath) => {
|
||||||
stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrDefault(childFilePath)));
|
if (!rootSource.has(childFilePath)) {
|
||||||
|
rootSource.set(childFilePath, observable.map());
|
||||||
|
}
|
||||||
|
|
||||||
|
stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.get(childFilePath)));
|
||||||
})
|
})
|
||||||
.on("unlink", (childFilePath) => {
|
.on("unlink", (childFilePath) => {
|
||||||
stoppers.get(childFilePath)();
|
stoppers.get(childFilePath)();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user