mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +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.
|
||||
* They allow components to retrieve data without knowing the store structure.
|
||||
* Exported functions must have unique names across all store modules.
|
||||
*
|
||||
* @file
|
||||
*/
|
||||
|
||||
import { STORE_KEY } from './constants';
|
||||
|
||||
const EMPTY_OBJ = Object.freeze( {} );
|
||||
|
||||
const getState = ( state ) => {
|
||||
if ( ! state ) {
|
||||
return EMPTY_OBJ;
|
||||
}
|
||||
const getState = ( state ) => state || EMPTY_OBJ;
|
||||
|
||||
return state[ STORE_KEY ] || EMPTY_OBJ;
|
||||
};
|
||||
|
||||
export const onboardingPersistentData = ( state ) => {
|
||||
export const persistentData = ( state ) => {
|
||||
return getState( state ).data || EMPTY_OBJ;
|
||||
};
|
||||
|
||||
export const onboardingTransientData = ( state ) => {
|
||||
export const transientData = ( state ) => {
|
||||
const { data, flags, ...transientState } = getState( state );
|
||||
return transientState || EMPTY_OBJ;
|
||||
};
|
||||
|
||||
export const onboardingFlags = ( state ) => {
|
||||
export const flags = ( state ) => {
|
||||
return getState( state ).flags || EMPTY_OBJ;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue