diff options
Diffstat (limited to 'apps/web/src/stores/keybindings/migrations/index.ts')
| -rw-r--r-- | apps/web/src/stores/keybindings/migrations/index.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/apps/web/src/stores/keybindings/migrations/index.ts b/apps/web/src/stores/keybindings/migrations/index.ts new file mode 100644 index 00000000..1689802e --- /dev/null +++ b/apps/web/src/stores/keybindings/migrations/index.ts @@ -0,0 +1,28 @@ +import { v2ToV3 } from './v2-to-v3'; + +type MigrationFn = ({ state }: { state: unknown }) => unknown; + +/** + * key = version we're migrating from + * value = migration function + */ +const migrations: Record<number, MigrationFn> = { + 2: v2ToV3, +}; + +export const CURRENT_VERSION = 3; + +export function runMigrations({ + state, + fromVersion, +}: { + state: unknown; + fromVersion: number; +}): unknown { + let current = state; + for (let version = fromVersion; version < CURRENT_VERSION; version++) { + const migrate = migrations[version]; + if (migrate) current = migrate({ state: current }); + } + return current; +} |
