1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Revert "Make BaseStore abstract (#1431)"

This reverts commit 4b56ab7c61.
This commit is contained in:
Alex Andreev 2020-11-20 07:51:43 +03:00
parent a975e3d456
commit 382687775b
3 changed files with 23 additions and 27 deletions

View File

@ -1,13 +1,11 @@
import { Store } from "@k8slens/extensions"; import { Store } from "@k8slens/extensions";
import { toJS } from "mobx" import { toJS } from "mobx"
export type TelemetryPreferencesModel = { export type TelemetryPreferencesModel = {
enabled: boolean; enabled: boolean;
} }
export class TelemetryPreferencesStore extends Store.ExtensionStore<TelemetryPreferencesModel> { export class TelemetryPreferencesStore extends Store.ExtensionStore<TelemetryPreferencesModel> {
enabled = true;
private constructor() { private constructor() {
super({ super({
configName: "preferences-store", configName: "preferences-store",
@ -17,13 +15,17 @@ export class TelemetryPreferencesStore extends Store.ExtensionStore<TelemetryPre
}) })
} }
protected fromStore({ enabled }: TelemetryPreferencesModel): void { get enabled() {
this.enabled = enabled return this.data.enabled
}
set enabled(v: boolean) {
this.data.enabled = v
} }
toJSON(): TelemetryPreferencesModel { toJSON(): TelemetryPreferencesModel {
return toJS({ return toJS({
enabled: this.enabled enabled: this.data.enabled
}, { }, {
recurseEverything: true recurseEverything: true
}) })

View File

@ -15,10 +15,7 @@ export interface BaseStoreParams<T = any> extends ConfOptions<T> {
syncOptions?: IReactionOptions; syncOptions?: IReactionOptions;
} }
/** export class BaseStore<T = any> extends Singleton {
* Note: T should only contain base JSON serializable types.
*/
export abstract class BaseStore<T = any> extends Singleton {
protected storeConfig: Config<T>; protected storeConfig: Config<T>;
protected syncDisposers: Function[] = []; protected syncDisposers: Function[] = [];
@ -149,19 +146,16 @@ export abstract class BaseStore<T = any> extends Singleton {
} }
} }
/** @action
* fromStore is called internally when a child class syncs with the file protected fromStore(data: T) {
* system. if (!data) return;
* @param data the parsed information read from the stored JSON file this.data = data;
*/ }
protected abstract fromStore(data: T): void;
/** // todo: use "serializr" ?
* toJSON is called when syncing the store to the filesystem. It should toJSON(): T {
* produce a JSON serializable object representaion of the current state. return toJS(this.data, {
* recurseEverything: true,
* It is recommended that a round trip is valid. Namely, calling })
* `this.fromStore(this.toJSON())` shouldn't change the state. }
*/
abstract toJSON(): T;
} }

View File

@ -2,17 +2,17 @@ import { BaseStore } from "../common/base-store"
import * as path from "path" import * as path from "path"
import { LensExtension } from "./lens-extension" import { LensExtension } from "./lens-extension"
export abstract class ExtensionStore<T> extends BaseStore<T> { export class ExtensionStore<T = any> extends BaseStore<T> {
protected extension: LensExtension protected extension: LensExtension
async loadExtension(extension: LensExtension) { async loadExtension(extension: LensExtension) {
this.extension = extension this.extension = extension
return super.load() await super.load()
} }
async load() { async load() {
if (!this.extension) { return } if (!this.extension) { return }
return super.load() await super.load()
} }
protected cwd() { protected cwd() {