mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix StorageHelp to initialize only once
- Don't create a box and then override it - Initial value should be the default value Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
63f6562e0a
commit
1bf4d4ce8b
@ -1,7 +1,7 @@
|
|||||||
// Helper for working with storages (e.g. window.localStorage, NodeJS/file-system, etc.)
|
// Helper for working with storages (e.g. window.localStorage, NodeJS/file-system, etc.)
|
||||||
|
|
||||||
import type { CreateObservableOptions } from "mobx/lib/api/observable";
|
import type { CreateObservableOptions } from "mobx/lib/api/observable";
|
||||||
import { action, comparer, observable, toJS, when } from "mobx";
|
import { action, comparer, observable, toJS, when, IObservableValue } from "mobx";
|
||||||
import produce, { Draft, enableMapSet, setAutoFreeze } from "immer";
|
import produce, { Draft, enableMapSet, setAutoFreeze } from "immer";
|
||||||
import { isEqual, isFunction, isPlainObject } from "lodash";
|
import { isEqual, isFunction, isPlainObject } from "lodash";
|
||||||
import logger from "../../main/logger";
|
import logger from "../../main/logger";
|
||||||
@ -33,7 +33,7 @@ export class StorageHelper<T> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@observable private data = observable.box<T>();
|
private data: IObservableValue<T>;
|
||||||
@observable initialized = false;
|
@observable initialized = false;
|
||||||
whenReady = when(() => this.initialized);
|
whenReady = when(() => this.initialized);
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ export class StorageHelper<T> {
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
private configureObservable(options = this.options.observable) {
|
private configureObservable(options = this.options.observable) {
|
||||||
this.data = observable.box<T>(this.data.get(), {
|
this.data = observable.box<T>(this.options.defaultValue, {
|
||||||
...StorageHelper.defaultOptions.observable, // inherit default observability options
|
...StorageHelper.defaultOptions.observable, // inherit default observability options
|
||||||
...(options ?? {}),
|
...(options ?? {}),
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user