Search code examples
ngrx

How to migrate out of date, persisted NgRx state


I'm looking to persist the application NgRx store to either local storage or a NoSQL database. This is so the application/user can resume from where they left the application last time they visited.

However, if the structure of the state has changed in my application the old persisted state will need to be migrated to the current one. Is there a way to do this with standard NgRx tooling or features or another popular pattern/method?


Solution

  • There is no generic way as far as I know, it's up to you to handle structure changes - we can't make those decisions for you.

    The answer also depends on what you store, is it the full state or are you storing the actions. Both are valid and serve different needs.

    If you're storing the full state, you'll have to provide a migration to migration from version 1 to version 2.

    If you're storing actions, you'll have to keep the reducer functions to handle those actions.