mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +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 reducer from './reducer';
|
||||||
import * as selectors from './selectors';
|
import * as selectors from './selectors';
|
||||||
import * as actions from './actions';
|
import * as actions from './actions';
|
||||||
import * as resolvers from './resolvers';
|
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 EMPTY_OBJ = Object.freeze( {} );
|
||||||
|
|
||||||
const getOnboardingState = ( state ) => {
|
const getState = ( state ) => {
|
||||||
if ( ! state ) {
|
if ( ! state ) {
|
||||||
return EMPTY_OBJ;
|
return EMPTY_OBJ;
|
||||||
}
|
}
|
||||||
|
|
||||||
return state.onboarding || EMPTY_OBJ;
|
return state[ STORE_KEY ] || EMPTY_OBJ;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPersistentData = ( state ) => {
|
export const getPersistentData = ( state ) => {
|
||||||
return getOnboardingState( state ).data || EMPTY_OBJ;
|
return getState( state ).data || EMPTY_OBJ;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getTransientData = ( state ) => {
|
export const getTransientData = ( state ) => {
|
||||||
const { data, flags, ...transientState } = getOnboardingState( state );
|
const { data, flags, ...transientState } = getState( state );
|
||||||
return transientState || EMPTY_OBJ;
|
return transientState || EMPTY_OBJ;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getFlags = ( state ) => {
|
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