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

support custom serialization/deserialization. fixes #75 #78

Merged
merged 1 commit into from
Jun 23, 2023

Conversation

jedelson-pagerduty
Copy link
Contributor

The solution described in #75 (comment) doesn't work (at least for my use case) because setItem accepts a string whereas I (and I suspect @tpict) need to control how stringify/parse actually work.

@polemius
Copy link
Owner

Could you please update documentation as well?

@jedelson-pagerduty
Copy link
Contributor Author

Could you please update documentation as well?

Done

Copy link
Owner

@polemius polemius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add mention of converter to Usage section

README.md Show resolved Hide resolved
@jedelson-pagerduty
Copy link
Contributor Author

Please add mention of converter to Usage section

I assume in the Usage section it makes sense to show the default but please let me know if you think something else should go there.

@polemius
Copy link
Owner

I assume in the Usage section it makes sense to show the default but please let me know if you think something else should go there.

I thought maybe we could show in Usage section all options like:

import { recoilPersist } from 'recoil-persist'

const { persistAtom } = recoilPersist({
  key: 'recoil-persist', // this key is using to store data in local storage
  storage: localStorage, // configurate which storage will be used to store the data
  converter: JSON, // .... 
})

@jedelson-pagerduty
Copy link
Contributor Author

Yeah, what I put there is

import { recoilPersist } from 'recoil-persist'
const { persistAtom } = recoilPersist({
  key: 'recoil-persist', // this key is using to store data in local storage
  storage: localStorage, // configurate which storage will be used to store the data
  converter: { // configurate how values will be serialized/deserialized in storage
    parse: (value) => JSON.parse,
    stringify: (value) =>  JSON.stringify
  }
})

Although converter: JSON would be semantically the same thing, I think it's useful to show both functions. WDYT?

@polemius
Copy link
Owner

converter: { // configurate how values will be serialized/deserialized in storage
    parse: (value) => JSON.parse(value),
    stringify: (value) =>  JSON.stringify(value)
}

you need to pass values to function

@polemius polemius merged commit 227e2e4 into polemius:master Jun 23, 2023
@polemius
Copy link
Owner

Good job! Thank you!

@polemius
Copy link
Owner

Released in 5.0.0 🚀

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

Successfully merging this pull request may close these issues.

None yet

2 participants