Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

persistStrategies with top level keys #4

Open
chrisdrackett opened this issue Jun 29, 2022 · 3 comments
Open

persistStrategies with top level keys #4

chrisdrackett opened this issue Jun 29, 2022 · 3 comments

Comments

@chrisdrackett
Copy link

I'm new to the library so many I'm missing something. Given the following top level state:

{ 
  userID: string, 
  photos: { 
    id: string, 
    url: string 
  } 
}

is there a way to persist photos using MultiFile while having userID in a single file? or do I need to add userID to a top level object?

@Noitidart
Copy link
Owner

Hi yes you can. Although I think userID might need to be an object. But please test and let me know if it works as string:

Here is how you would do:

const appStateProxy = proxyWithPersist({
  // must be unique, files/paths will be created with this prefix
  name: 'appState',

  initialState: {
    counter: 0,
  },
  persistStrategies: {
    userID: PersistStrategy.SingleFile,
    photos: PersistStrategy.MultiFile,
  },
  version: 0,
  migrations: {},

  // see "Storage Engine" section below
  getStorage: () => storage,
});

@chrisdrackett
Copy link
Author

yeah, I just ended up putting userID in an object. If I don't it just silently fails :D

@Noitidart
Copy link
Owner

Ah thanks for sharing that. I'll document that. I also want to plan to update this lib to support more situations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants