♻️ 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.
* They allow components to retrieve data without knowing the store structure.
* Exported functions must have unique names across all store modules.
*
* @file
*/
import { STORE_KEY } from './constants';
const EMPTY_OBJ = Object.freeze( {} );
const getState = ( state ) => {
if ( ! state ) {
return EMPTY_OBJ;
}
const getState = ( state ) => state || EMPTY_OBJ;
return state[ STORE_KEY ] || EMPTY_OBJ;
};
export const onboardingPersistentData = ( state ) => {
export const persistentData = ( state ) => {
return getState( state ).data || EMPTY_OBJ;
};
export const onboardingTransientData = ( state ) => {
export const transientData = ( state ) => {
const { data, flags, ...transientState } = getState( state );
return transientState || EMPTY_OBJ;
};
export const onboardingFlags = ( state ) => {
export const flags = ( state ) => {
return getState( state ).flags || EMPTY_OBJ;
};