Skip to content

Any way to persist a nested class? what would be the right way to handle class like that with nano stores? #217

Closed Answered by ai
rozenstein94 asked this question in Q&A
Discussion options

You must be logged in to vote

Looks like you want to keep too many in a single store.

I suggest having 2 different stores. One for patients from the server. The second for the client-side draft. Just use the same type to share the keys between them.

interface Patient {
  id: number;
  name: string;
  medicalHistory: string[];
}

let patientDraft = persistentMap<Patient>(emptyPatient, {
  encode: JSON.stringify,
  decode: JSON.parse
})

To load data from server you can use Nano Store Query or write your own store:

type RemotePatient =
  | { id: string, isLoading: true }
  | { id: string, isLoading: false, error: 'notFound' |  }
  | { id: string, isLoading: false } & Patient

let cache = {}

function createPatient(id: s…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@rozenstein94
Comment options

@ai
Comment options

@rozenstein94
Comment options

@ai
Comment options

Answer selected by rozenstein94
@rozenstein94
Comment options

@ai
Comment options

@rozenstein94
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants