♻️ Simplify selectors

This commit is contained in:
Philipp Stracker 2024-11-20 16:54:11 +01:00
parent 4d84bdbd43
commit 329135d1dc
No known key found for this signature in database

View file

@ -3,32 +3,23 @@
* *
* These functions provide a consistent interface for accessing store data. * These functions provide a consistent interface for accessing store data.
* They allow components to retrieve data without knowing the store structure. * They allow components to retrieve data without knowing the store structure.
* Exported functions must have unique names across all store modules.
* *
* @file * @file
*/ */
import { STORE_KEY } from './constants';
const EMPTY_OBJ = Object.freeze( {} ); const EMPTY_OBJ = Object.freeze( {} );
const getState = ( state ) => { const getState = ( state ) => state || EMPTY_OBJ;
if ( ! state ) {
return EMPTY_OBJ;
}
return state[ STORE_KEY ] || EMPTY_OBJ; export const persistentData = ( state ) => {
};
export const onboardingPersistentData = ( state ) => {
return getState( state ).data || EMPTY_OBJ; return getState( state ).data || EMPTY_OBJ;
}; };
export const onboardingTransientData = ( state ) => { export const transientData = ( state ) => {
const { data, flags, ...transientState } = getState( state ); const { data, flags, ...transientState } = getState( state );
return transientState || EMPTY_OBJ; return transientState || EMPTY_OBJ;
}; };
export const onboardingFlags = ( state ) => { export const flags = ( state ) => {
return getState( state ).flags || EMPTY_OBJ; return getState( state ).flags || EMPTY_OBJ;
}; };