♻️ Location-prop accessors require a location arg

Instead of using the “location” property, we want to explicitly specify which location props to access
This commit is contained in:
Philipp Stracker 2025-01-17 13:04:21 +01:00
parent 510a711caa
commit a5ceec2af4
No known key found for this signature in database

View file

@ -23,8 +23,8 @@ import {
} from './configuration'; } from './configuration';
const useHooks = () => { const useHooks = () => {
const { useTransient, usePersistent } = createHooksForStore( STORE_NAME ); const { useTransient } = createHooksForStore( STORE_NAME );
const { persist } = useDispatch( STORE_NAME ); const { persist, setPersistent } = useDispatch( STORE_NAME );
// Read-only flags and derived state. // Read-only flags and derived state.
@ -38,28 +38,28 @@ const useHooks = () => {
[] []
); );
const [ locationStyles, setLocationStyles ] = usePersistent( location );
const getLocationProp = useCallback( const getLocationProp = useCallback(
( prop ) => { ( locatonId, prop ) => {
if ( undefined === persistentData[ location ]?.[ prop ] ) { if ( undefined === persistentData[ locatonId ]?.[ prop ] ) {
console.error( console.error(
`Trying to access non-existent style property: ${ location }.${ prop }. Possibly wrong style name - review the reducer.` `Trying to access non-existent style property: ${ locatonId }.${ prop }. Possibly wrong style name - review the reducer.`
); );
} }
return persistentData[ location ]?.[ prop ]; return persistentData[ locatonId ]?.[ prop ];
}, },
[ location, persistentData ] [ persistentData ]
); );
const setLocationProp = useCallback( const setLocationProp = useCallback(
( prop, value ) => { ( locationId, prop, value ) => {
setLocationStyles( { const updatedStyles = {
...locationStyles, ...persistentData[ locationId ],
[ prop ]: value, [ prop ]: value,
} ); };
setPersistent( locationId, updatedStyles );
}, },
[ locationStyles, setLocationStyles ] [ persistentData, setPersistent ]
); );
return { return {