Skip to content

Commit

Permalink
store [nfc]: Slightly simplify migrations; clarify comments.
Browse files Browse the repository at this point in the history
In particular, in migration 12 there's no need to check on the
existing `a.zulipVersion`; that property must be missing, because in
versions of the app before we added that migration it didn't exist.
  • Loading branch information
gnprice committed Sep 19, 2020
1 parent d11c3b4 commit e122cfb
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/boot/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ const migrations: { [string]: (GlobalState) => GlobalState } = {
accounts: state.accounts.map(a => ({
...a,
// but in the case of `ackedPushToken` let's be a bit more precise,
// and avoid clobbering it if present.
// and avoid clobbering it if present. (Don't copy this pattern for a
// normal migration; this uncertainty is specific to recovering from #3553.)
ackedPushToken: a.ackedPushToken !== undefined ? a.ackedPushToken : null,
})),
}),
Expand Down Expand Up @@ -159,26 +160,25 @@ const migrations: { [string]: (GlobalState) => GlobalState } = {
})),
}),

// Accounts.zulipVersion is now string | null
// Add Accounts.zulipVersion, as string | null.
'12': state => ({
...state,
accounts: state.accounts.map(a => ({
...a,
zulipVersion: a.zulipVersion !== undefined ? a.zulipVersion : null,
zulipVersion: null,
})),
}),

// Accounts.zulipVersion is now ZulipVersion | null
// Convert Accounts.zulipVersion from `string | null` to `ZulipVersion | null`.
'13': state => ({
...state,
accounts: state.accounts.map(a => ({
...a,
zulipVersion:
typeof a.zulipVersion === 'string' ? new ZulipVersion(a.zulipVersion) : a.zulipVersion,
zulipVersion: typeof a.zulipVersion === 'string' ? new ZulipVersion(a.zulipVersion) : null,
})),
}),

// Added Accounts.zulipFeatureLevel as number | null
// Add Accounts.zulipFeatureLevel, as number | null.
'14': state => ({
...state,
accounts: state.accounts.map(a => ({
Expand Down

0 comments on commit e122cfb

Please sign in to comment.