2024-11-18 18:51:11 +01:00
|
|
|
/**
|
|
|
|
* Selectors: Extract specific pieces of state from the store.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2024-11-18 16:25:57 +01:00
|
|
|
import { STORE_KEY } from './constants';
|
|
|
|
|
2024-10-23 18:11:09 +02:00
|
|
|
const EMPTY_OBJ = Object.freeze( {} );
|
2024-10-22 15:15:55 +02:00
|
|
|
|
2024-11-18 16:25:57 +01:00
|
|
|
const getState = ( state ) => {
|
2024-10-22 15:15:55 +02:00
|
|
|
if ( ! state ) {
|
|
|
|
return EMPTY_OBJ;
|
|
|
|
}
|
|
|
|
|
2024-11-18 16:25:57 +01:00
|
|
|
return state[ STORE_KEY ] || EMPTY_OBJ;
|
2024-10-22 15:15:55 +02:00
|
|
|
};
|
|
|
|
|
2024-11-18 18:26:10 +01:00
|
|
|
export const onboardingPersistentData = ( state ) => {
|
2024-11-18 16:25:57 +01:00
|
|
|
return getState( state ).data || EMPTY_OBJ;
|
2024-10-22 15:15:55 +02:00
|
|
|
};
|
|
|
|
|
2024-11-18 18:26:10 +01:00
|
|
|
export const onboardingTransientData = ( state ) => {
|
2024-11-18 16:25:57 +01:00
|
|
|
const { data, flags, ...transientState } = getState( state );
|
2024-10-23 18:11:09 +02:00
|
|
|
return transientState || EMPTY_OBJ;
|
2024-10-22 18:56:37 +02:00
|
|
|
};
|
2024-10-30 16:52:06 +01:00
|
|
|
|
2024-11-18 18:26:10 +01:00
|
|
|
export const onboardingFlags = ( state ) => {
|
2024-11-18 16:25:57 +01:00
|
|
|
return getState( state ).flags || EMPTY_OBJ;
|
2024-10-30 16:52:06 +01:00
|
|
|
};
|