mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
♻️ Rename selector to prepare changes
This commit is contained in:
parent
3d037fde27
commit
c3a81434c4
2 changed files with 31 additions and 9 deletions
|
@ -12,6 +12,31 @@ import { useSelect, useDispatch } from '@wordpress/data';
|
||||||
import { createHooksForStore } from '../utils';
|
import { createHooksForStore } from '../utils';
|
||||||
import { PRODUCT_TYPES } from './configuration';
|
import { PRODUCT_TYPES } from './configuration';
|
||||||
import { STORE_NAME } from './constants';
|
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 useHooks = () => {
|
||||||
const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
|
const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
|
||||||
|
@ -19,10 +44,6 @@ const useHooks = () => {
|
||||||
|
|
||||||
// Read-only flags and derived state.
|
// Read-only flags and derived state.
|
||||||
const flags = useSelect( ( select ) => select( STORE_NAME ).flags(), [] );
|
const flags = useSelect( ( select ) => select( STORE_NAME ).flags(), [] );
|
||||||
const determineProducts = useSelect(
|
|
||||||
( select ) => select( STORE_NAME ).determineProducts(),
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Transient accessors.
|
// Transient accessors.
|
||||||
const [ isReady ] = useTransient( 'isReady' );
|
const [ isReady ] = useTransient( 'isReady' );
|
||||||
|
@ -80,7 +101,6 @@ const useHooks = () => {
|
||||||
);
|
);
|
||||||
return savePersistent( setProducts, validProducts );
|
return savePersistent( setProducts, validProducts );
|
||||||
},
|
},
|
||||||
determineProducts,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -141,9 +161,10 @@ export const useNavigationState = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useDetermineProducts = () => {
|
export const useDetermineProducts = () => {
|
||||||
const { determineProducts } = useHooks();
|
const { select } = useStoreData();
|
||||||
|
const { determineProductsAndCaps } = select;
|
||||||
|
|
||||||
return determineProducts;
|
return determineProductsAndCaps;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useFlags = () => {
|
export const useFlags = () => {
|
||||||
|
|
|
@ -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
|
* This selector does not return state-values, but uses the state to derive the products-array
|
||||||
* that should be returned.
|
* that should be returned.
|
||||||
|
@ -33,7 +34,7 @@ export const flags = ( state ) => {
|
||||||
* @param {{}} state
|
* @param {{}} state
|
||||||
* @return {string[]} The ISU products, based on choices made in the onboarding wizard.
|
* @return {string[]} The ISU products, based on choices made in the onboarding wizard.
|
||||||
*/
|
*/
|
||||||
export const determineProducts = ( state ) => {
|
export const determineProductsAndCaps = ( state ) => {
|
||||||
const derivedProducts = [];
|
const derivedProducts = [];
|
||||||
|
|
||||||
const { isCasualSeller, areOptionalPaymentMethodsEnabled } =
|
const { isCasualSeller, areOptionalPaymentMethodsEnabled } =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue