♻️ Introduce new STORE_KEY const

This commit is contained in:
Philipp Stracker 2024-11-18 16:25:57 +01:00
parent 4dd31965ea
commit cf3798f610
No known key found for this signature in database
3 changed files with 19 additions and 6 deletions

View file

@ -0,0 +1,10 @@
/**
* Name of the module-store in the main Redux store.
* Helps to isolate data.
*
* Used by: Reducer, Selector, Index
*
* @type {string}
*/
export const STORE_KEY = 'onboarding';

View file

@ -1,6 +1,7 @@
import { STORE_KEY } from './constants';
import reducer from './reducer';
import * as selectors from './selectors';
import * as actions from './actions';
import * as resolvers from './resolvers';
export { reducer, selectors, actions, resolvers };
export { reducer, selectors, actions, resolvers, STORE_KEY };

View file

@ -1,22 +1,24 @@
import { STORE_KEY } from './constants';
const EMPTY_OBJ = Object.freeze( {} );
const getOnboardingState = ( state ) => {
const getState = ( state ) => {
if ( ! state ) {
return EMPTY_OBJ;
}
return state.onboarding || EMPTY_OBJ;
return state[ STORE_KEY ] || EMPTY_OBJ;
};
export const getPersistentData = ( state ) => {
return getOnboardingState( state ).data || EMPTY_OBJ;
return getState( state ).data || EMPTY_OBJ;
};
export const getTransientData = ( state ) => {
const { data, flags, ...transientState } = getOnboardingState( state );
const { data, flags, ...transientState } = getState( state );
return transientState || EMPTY_OBJ;
};
export const getFlags = ( state ) => {
return getOnboardingState( state ).flags || EMPTY_OBJ;
return getState( state ).flags || EMPTY_OBJ;
};