mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
♻️ Introduce new STORE_KEY const
This commit is contained in:
parent
4dd31965ea
commit
cf3798f610
3 changed files with 19 additions and 6 deletions
|
@ -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';
|
||||
|
|
@ -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 };
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue