woocommerce-paypal-payments/modules/ppcp-settings/resources/js/data/common/selectors.js
Philipp Stracker 9aad1274bc
♻️ Move the branded-only-flag into wooSettings
The flag must not appear in the “defaultPersistent” object, as this would allow users to modify the state when saving settings!

Instead, the installation path moved into the read-only object “wooSettings”
2025-03-21 17:51:19 +01:00

60 lines
1.4 KiB
JavaScript

/**
* Selectors: Extract specific pieces of state from the store.
*
* These functions provide a consistent interface for accessing store data.
* They allow components to retrieve data without knowing the store structure.
*
* @file
*/
const EMPTY_OBJ = Object.freeze( {} );
const getState = ( state ) => state || EMPTY_OBJ;
export const persistentData = ( state ) => {
return getState( state ).data || EMPTY_OBJ;
};
export const transientData = ( state ) => {
const {
data,
merchant,
features,
wooSettings,
webhooks,
...transientState
} = getState( state );
return transientState || EMPTY_OBJ;
};
export const getActivityList = ( state ) => {
const { activities = new Map() } = state;
return Object.fromEntries( activities );
};
export const merchant = ( state ) => {
return getState( state ).merchant || EMPTY_OBJ;
};
export const features = ( state ) => {
return getState( state ).features || EMPTY_OBJ;
};
export const wooSettings = ( state ) => {
const settings = getState( state ).wooSettings || EMPTY_OBJ;
/**
* The "is branded only experience" is determined based on the installation path.
*
* @type {boolean}
*/
settings.isBranded =
settings.installationPath === 'core-profile' ||
settings.installationPath === 'payment-settings';
return settings;
};
export const webhooks = ( state ) => {
return getState( state ).webhooks || EMPTY_OBJ;
};