Switch UserStore to injectable migrations

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2022-12-06 09:18:59 -05:00
1 parent 1aa3e46262
commit 3958e613ec
9 files changed
+143 -150

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { MigrationDeclaration } from "../base-store/migrations.injectable";
export const userStoreMigrationInjectionToken = getInjectionToken<MigrationDeclaration>({
id: "user-store-migration-token",
});
@@ -10,6 +10,8 @@ import directoryForUserDataInjectable from "../app-paths/directory-for-user-data
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
import loggerInjectable from "../logger.injectable";
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
import storeMigrationsInjectable from "../base-store/migrations.injectable";
import { userStoreMigrationInjectionToken } from "./migrations-token";
const userStoreInjectable = getInjectable({
id: "user-store",
@@ -21,6 +23,7 @@ const userStoreInjectable = getInjectable({
getConfigurationFileModel: di.inject(getConfigurationFileModelInjectable),
logger: di.inject(loggerInjectable),
storeMigrationVersion: di.inject(storeMigrationVersionInjectable),
migrations: di.inject(storeMigrationsInjectable, userStoreMigrationInjectionToken),
}),
});
+2 -14
View File
@@ -7,7 +7,6 @@ import { app } from "electron";
import { action, observable, reaction, makeObservable, isObservableArray, isObservableSet, isObservableMap } from "mobx";
import type { BaseStoreDependencies } from "../base-store/base-store";
import { BaseStore } from "../base-store/base-store";
import migrations from "../../migrations/user-store";
import { getOrInsertSet, toggle, toJS, object } from "../../renderer/utils";
import { DESCRIPTORS } from "./preferences-helpers";
import type { UserPreferencesModel, StoreType } from "./preferences-helpers";
@@ -18,7 +17,6 @@ import type { SelectedUpdateChannel } from "../../features/application-update/co
import type { ReleaseChannel } from "../../features/application-update/common/update-channels";
export interface UserStoreModel {
lastSeenAppVersion: string;
preferences: UserPreferencesModel;
}
@@ -33,14 +31,11 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
constructor(protected readonly dependencies: Dependencies) {
super(dependencies, {
configName: "lens-user-store",
migrations,
});
makeObservable(this);
}
@observable lastSeenAppVersion = "0.0.0";
/**
* @deprecated No longer used
*/
@@ -137,12 +132,8 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
}
@action
protected fromStore({ lastSeenAppVersion, preferences }: Partial<UserStoreModel> = {}) {
this.dependencies.logger.debug("UserStore.fromStore()", { lastSeenAppVersion, preferences });
if (lastSeenAppVersion) {
this.lastSeenAppVersion = lastSeenAppVersion;
}
protected fromStore({ preferences }: Partial<UserStoreModel> = {}) {
this.dependencies.logger.debug("UserStore.fromStore()", { preferences });
for (const [key, { fromStore }] of object.entries(DESCRIPTORS)) {
const curVal = this[key];
@@ -170,11 +161,8 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
) as UserPreferencesModel;
return toJS({
lastSeenAppVersion: this.lastSeenAppVersion,
preferences: {
...preferences,
updateChannel: this.dependencies.selectedUpdateChannel.value.get().id,
},
});