Browse Source

fix: borked v3->v4 feat config migration

Sven 1 năm trước cách đây
mục cha
commit
d11f632459
1 tập tin đã thay đổi với 9 bổ sung11 xóa
  1. 9 11
      src/config.ts

+ 9 - 11
src/config.ts

@@ -23,14 +23,16 @@ export const migrations: ConfigMigrationsDict = {
   // 2 -> 3
   3: (oldData: FeatureConfig) => useDefaultConfig([
     "removeShareTrackingParam", "numKeysSkipToTime",
-    "fixSpacing", "scrollToActiveSongBtn",
-    "logLevel",
+    "fixSpacing", "scrollToActiveSongBtn", "logLevel",
   ], oldData),
   // 3 -> 4
   4: (oldData: FeatureConfig) => {
     const oldSwitchSitesHotkey = oldData.switchSitesHotkey as Record<string, unknown>;
     return {
-      ...oldData,
+      ...useDefaultConfig([
+        "rememberSongTime", "rememberSongTimeSites",
+        "volumeSliderScrollStep", "locale", "versionCheck",
+      ], oldData),
       arrowKeySkipBy: 10,
       switchSitesHotkey: {
         code: oldSwitchSitesHotkey.key ?? "F9",
@@ -39,11 +41,6 @@ export const migrations: ConfigMigrationsDict = {
         alt: Boolean(oldSwitchSitesHotkey.meta ?? false),
       },
       listButtonsPlacement: "queueOnly",
-      ...useDefaultConfig([
-        "rememberSongTime", "rememberSongTimeSites",
-        "volumeSliderScrollStep", "locale",
-        "versionCheck",
-      ], oldData),
     };
   },
   // 4 -> 5
@@ -56,14 +53,15 @@ export const migrations: ConfigMigrationsDict = {
   ], oldData),
 };
 
-/** Uses the passed `oldData` as the base and sets all passed `keys` to their feature default - returns a copy of the object */
-function useDefaultConfig(keys: (keyof typeof featInfo)[], oldData: FeatureConfig): Partial<FeatureConfig> {
-  const newData = { ...oldData };
+/** Uses the passed {@linkcode oldData} as the base (if given) and sets all passed {@linkcode keys} to their feature default - returns a copy of the object */
+function useDefaultConfig(keys: (keyof typeof featInfo)[], oldData?: FeatureConfig): Partial<FeatureConfig> {
+  const newData = { ...(oldData ?? {}) };
   for(const key of keys)
     newData[key as keyof typeof featInfo] = getFeatureDefault(key as keyof typeof featInfo) as unknown as never;
   return newData;
 }
 
+/** Returns the default value for the given feature key */
 function getFeatureDefault<TKey extends keyof typeof featInfo>(key: TKey): typeof featInfo[TKey]["default"] {
   return featInfo[key].default;
 }