-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Es/example of persisted state #747
Es/example of persisted state #747
Conversation
backgroundMapStoreSlice, | ||
'background-maps' | ||
) | ||
export const usePersistedUiStore = createPersistedStore( | ||
persistedUiStoreSlice, | ||
'ui' | ||
) | ||
|
||
export const useBackgroundMapStore = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now this hooks encapsulates the logic for whether background maps is enable or not. And can only show and set the maps that are relevant to that state. No need to the developer to do a check everytime.
src/renderer/hooks/store.js
Outdated
: [store.mapStyleLegacy, store.setMapStyleLegacy] | ||
) | ||
|
||
return { mapStyle, setMapStyle } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally this would return an array, but I am not too sure how to the equivalent of as const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data: !legacyStyleQueryResult.data | ||
? [defaultMapStyle] | ||
: legacyStyleQueryResult.data, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this encapsulates the undefined check so the consuming components do not have to do that
src/renderer/hooks/store.js
Outdated
const DEFAULT_MAP = { | ||
id: '487x2pc8ws801avhs5hw58qnxc', | ||
url: 'mapbox://styles/mapbox/outdoors-v10', | ||
bytesStored: 0, | ||
name: m.defaultBackgroundMapName, | ||
isImporting: false, | ||
isDefault: true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in 2 places, so ideally should just be moved to one place!
Hey this makes sense. I've wrapped up the loose ends on this so it can be merged if you're happy with it |
this is incomplete, but I wanted to show an example of encapsulating the logic of whether background maps is on or off directly in the hook.
Also example of doing undefined check inside the useMapStylesQuery hook