4 ms·
We did the same at a previous company. This was Redux, so maybe a little different, but it went very smoothly. We stored a subset of the redux store locally, a
by mikewhy 6y ago
We did the same at a previous company. This was Redux, so maybe a little different, but it went very smoothly.
We stored a subset of the redux store locally, and a further subset of that was sent to the server. This data is quite prone to changing, so a JSON field in the database is fine. You're not going to do any advanced querying / migrations on it.
Restoring was pretty easy:
- Try to grab from local storage
- Try to read from remote
- Merge those (let local overwrite remote)
- Pass the merged object through a migration function
- Pass the migrated data to `createStore`
The biggest pain point was dealing with TypeScript and migrations. The app only knows if the most recent store interface, so migration functions looked a lot like "old" javascript (`if (foo && foo.bar)`, `typeof foo === 'string'`, that sort of stuff).
Easy persistence / restoring is one of the many things I like about Redux.
- bitten 6y agoYou can express a type as one of many interfaces, or use discriminated unions (https://www.typescriptlang.org/docs/handbook/advanced-types.html#discriminated-unions https://www.typescriptlang.org/docs/handbook/advanced-types....) by using some unique version key to identify each interface. Then you'll have all the goodness of types back :)