Skip to content

Commit

Permalink
Use Partial instead of RecursivePartial for persisted state
Browse files Browse the repository at this point in the history
The current state metadata takes an all-or-nothing approach to
persisting each state property. There is no mechanism for omitting
nested properties from the persisted state. As such, `Partial` is a
better description of the return type than `RecursivePartial`.
  • Loading branch information
Gudahtt committed Feb 25, 2021
1 parent 339818f commit 56b9d1b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/BaseControllerV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ export function getAnonymizedState<S extends Record<string, any>>(
export function getPersistentState<S extends Record<string, any>>(
state: S,
metadata: StateMetadata<S>,
): RecursivePartial<S> {
): Partial<S> {
return Object.keys(state).reduce((persistedState, _key) => {
const key: keyof S = _key; // https://stackoverflow.com/questions/63893394/string-cannot-be-used-to-index-type-t
if (metadata[key].persist) {
persistedState[key] = state[key];
}
return persistedState;
}, {} as RecursivePartial<S>);
}, {} as Partial<S>);
}

0 comments on commit 56b9d1b

Please sign in to comment.