mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 12:25:15 +08:00
♻️ Simplify selectors
This commit is contained in:
parent
4d84bdbd43
commit
329135d1dc
1 changed files with 4 additions and 13 deletions
|
@ -3,32 +3,23 @@
|
||||||
*
|
*
|
||||||
* These functions provide a consistent interface for accessing store data.
|
* These functions provide a consistent interface for accessing store data.
|
||||||
* They allow components to retrieve data without knowing the store structure.
|
* They allow components to retrieve data without knowing the store structure.
|
||||||
* Exported functions must have unique names across all store modules.
|
|
||||||
*
|
*
|
||||||
* @file
|
* @file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { STORE_KEY } from './constants';
|
|
||||||
|
|
||||||
const EMPTY_OBJ = Object.freeze( {} );
|
const EMPTY_OBJ = Object.freeze( {} );
|
||||||
|
|
||||||
const getState = ( state ) => {
|
const getState = ( state ) => state || EMPTY_OBJ;
|
||||||
if ( ! state ) {
|
|
||||||
return EMPTY_OBJ;
|
|
||||||
}
|
|
||||||
|
|
||||||
return state[ STORE_KEY ] || EMPTY_OBJ;
|
export const persistentData = ( state ) => {
|
||||||
};
|
|
||||||
|
|
||||||
export const onboardingPersistentData = ( state ) => {
|
|
||||||
return getState( state ).data || EMPTY_OBJ;
|
return getState( state ).data || EMPTY_OBJ;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const onboardingTransientData = ( state ) => {
|
export const transientData = ( state ) => {
|
||||||
const { data, flags, ...transientState } = getState( state );
|
const { data, flags, ...transientState } = getState( state );
|
||||||
return transientState || EMPTY_OBJ;
|
return transientState || EMPTY_OBJ;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const onboardingFlags = ( state ) => {
|
export const flags = ( state ) => {
|
||||||
return getState( state ).flags || EMPTY_OBJ;
|
return getState( state ).flags || EMPTY_OBJ;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue