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

Ej/fix persisted store #746

Merged
merged 11 commits into from
Aug 22, 2023
19 changes: 5 additions & 14 deletions src/renderer/hooks/store.js
Copy link
Contributor

Choose a reason for hiding this comment

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

based on the typescript typings, it looks like get item has to return a string, and I assume createJSONStorage then just turns it back to an object...its seems like it is working.

playing around with it, I also realize that getItem, setItem, and removeItem don't need jsdoc typings, those are encapasulated it typing of the 'storage'

Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,15 @@ import store from '../../persist-store'
* @type {import('zustand/middleware').StateStorage}
*/
const storage = {
/**
* @param {string} key - A string key to reference the stored item by.
* @returns {string | null}
*/
getItem: key => {
return /** @type {string | null} */ (store.get(key)) || null
/**
* @type {string | null}
*/
return store.get(key, null)
},
/**
* @param {string} key - A string key to reference the stored item by.
* @param {string} state - The state to be persisted - stringified JSON.
* @returns {void}
*/
setItem: (key, state) => {
store.set(key, JSON.parse(state))
store.set(key, state)
},
/**
* @param {string} key - A string key to reference the stored item to be removed.
*/
removeItem: key => {
store.delete(key)
}
Expand Down
Loading