♻️ Rename selector to prepare changes

This commit is contained in:
Philipp Stracker 2025-02-20 18:32:57 +01:00
parent 3d037fde27
commit c3a81434c4
No known key found for this signature in database
2 changed files with 31 additions and 9 deletions

View file

@ -12,6 +12,31 @@ import { useSelect, useDispatch } from '@wordpress/data';
import { createHooksForStore } from '../utils';
import { PRODUCT_TYPES } from './configuration';
import { STORE_NAME } from './constants';
import { useMemo } from '@wordpress/element';
/**
* Single source of truth for access Redux details.
*
* This hook returns a stable API to access actions, selectors and special hooks to generate
* getter- and setters for transient or persistent properties.
*
* @return {{select, dispatch, useTransient, usePersistent}} Store data API.
*/
const useStoreData = () => {
const select = useSelect( ( selectors ) => selectors( STORE_NAME ), [] );
const dispatch = useDispatch( STORE_NAME );
const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
return useMemo(
() => ( {
select,
dispatch,
useTransient,
usePersistent,
} ),
[ select, dispatch, useTransient, usePersistent ]
);
};
const useHooks = () => {
const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
@ -19,10 +44,6 @@ const useHooks = () => {
// Read-only flags and derived state.
const flags = useSelect( ( select ) => select( STORE_NAME ).flags(), [] );
const determineProducts = useSelect(
( select ) => select( STORE_NAME ).determineProducts(),
[]
);
// Transient accessors.
const [ isReady ] = useTransient( 'isReady' );
@ -80,7 +101,6 @@ const useHooks = () => {
);
return savePersistent( setProducts, validProducts );
},
determineProducts,
};
};
@ -141,9 +161,10 @@ export const useNavigationState = () => {
};
export const useDetermineProducts = () => {
const { determineProducts } = useHooks();
const { select } = useStoreData();
const { determineProductsAndCaps } = select;
return determineProducts;
return determineProductsAndCaps;
};
export const useFlags = () => {

View file

@ -25,7 +25,8 @@ export const flags = ( state ) => {
};
/**
* Returns the products that we use for the production login link in the last onboarding step.
* Returns details about products and capabilities to use for the production login link in
* the last onboarding step.
*
* This selector does not return state-values, but uses the state to derive the products-array
* that should be returned.
@ -33,7 +34,7 @@ export const flags = ( state ) => {
* @param {{}} state
* @return {string[]} The ISU products, based on choices made in the onboarding wizard.
*/
export const determineProducts = ( state ) => {
export const determineProductsAndCaps = ( state ) => {
const derivedProducts = [];
const { isCasualSeller, areOptionalPaymentMethodsEnabled } =