mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
♻️ Apple new code style to common store
This commit is contained in:
parent
4d38c15b29
commit
77ed657394
2 changed files with 40 additions and 46 deletions
|
@ -36,16 +36,37 @@ export const hydrate = ( payload ) => ( {
|
||||||
payload,
|
payload,
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic transient-data updater.
|
||||||
|
*
|
||||||
|
* @param {string} prop Name of the property to update.
|
||||||
|
* @param {any} value The new value of the property.
|
||||||
|
* @return {Action} The action.
|
||||||
|
*/
|
||||||
|
export const setTransient = ( prop, value ) => ( {
|
||||||
|
type: ACTION_TYPES.SET_TRANSIENT,
|
||||||
|
payload: { [ prop ]: value },
|
||||||
|
} );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic persistent-data updater.
|
||||||
|
*
|
||||||
|
* @param {string} prop Name of the property to update.
|
||||||
|
* @param {any} value The new value of the property.
|
||||||
|
* @return {Action} The action.
|
||||||
|
*/
|
||||||
|
export const setPersistent = ( prop, value ) => ( {
|
||||||
|
type: ACTION_TYPES.SET_PERSISTENT,
|
||||||
|
payload: { [ prop ]: value },
|
||||||
|
} );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transient. Marks the onboarding details as "ready", i.e., fully initialized.
|
* Transient. Marks the onboarding details as "ready", i.e., fully initialized.
|
||||||
*
|
*
|
||||||
* @param {boolean} isReady
|
* @param {boolean} isReady
|
||||||
* @return {Action} The action.
|
* @return {Action} The action.
|
||||||
*/
|
*/
|
||||||
export const setIsReady = ( isReady ) => ( {
|
export const setIsReady = ( isReady ) => setTransient( 'isReady', isReady );
|
||||||
type: ACTION_TYPES.SET_TRANSIENT,
|
|
||||||
payload: { isReady },
|
|
||||||
} );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transient. Sets the active settings tab.
|
* Transient. Sets the active settings tab.
|
||||||
|
@ -53,21 +74,8 @@ export const setIsReady = ( isReady ) => ( {
|
||||||
* @param {string} activeModal
|
* @param {string} activeModal
|
||||||
* @return {Action} The action.
|
* @return {Action} The action.
|
||||||
*/
|
*/
|
||||||
export const setActiveModal = ( activeModal ) => ( {
|
export const setActiveModal = ( activeModal ) =>
|
||||||
type: ACTION_TYPES.SET_TRANSIENT,
|
setTransient( 'activeModal', activeModal );
|
||||||
payload: { activeModal },
|
|
||||||
} );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transient. Changes the "saving" flag.
|
|
||||||
*
|
|
||||||
* @param {boolean} isSaving
|
|
||||||
* @return {Action} The action.
|
|
||||||
*/
|
|
||||||
export const setIsSaving = ( isSaving ) => ( {
|
|
||||||
type: ACTION_TYPES.SET_TRANSIENT,
|
|
||||||
payload: { isSaving },
|
|
||||||
} );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transient (Activity): Marks the start of an async activity
|
* Transient (Activity): Marks the start of an async activity
|
||||||
|
@ -107,10 +115,8 @@ export const stopActivity = ( id ) => ( {
|
||||||
* @param {boolean} useSandbox
|
* @param {boolean} useSandbox
|
||||||
* @return {Action} The action.
|
* @return {Action} The action.
|
||||||
*/
|
*/
|
||||||
export const setSandboxMode = ( useSandbox ) => ( {
|
export const setSandboxMode = ( useSandbox ) =>
|
||||||
type: ACTION_TYPES.SET_PERSISTENT,
|
setPersistent( 'useSandbox', useSandbox );
|
||||||
payload: { useSandbox },
|
|
||||||
} );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persistent. Toggles the "Manual Connection" mode on or off.
|
* Persistent. Toggles the "Manual Connection" mode on or off.
|
||||||
|
@ -118,10 +124,8 @@ export const setSandboxMode = ( useSandbox ) => ( {
|
||||||
* @param {boolean} useManualConnection
|
* @param {boolean} useManualConnection
|
||||||
* @return {Action} The action.
|
* @return {Action} The action.
|
||||||
*/
|
*/
|
||||||
export const setManualConnectionMode = ( useManualConnection ) => ( {
|
export const setManualConnectionMode = ( useManualConnection ) =>
|
||||||
type: ACTION_TYPES.SET_PERSISTENT,
|
setPersistent( 'useManualConnection', useManualConnection );
|
||||||
payload: { useManualConnection },
|
|
||||||
} );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Side effect. Saves the persistent details to the WP database.
|
* Side effect. Saves the persistent details to the WP database.
|
||||||
|
|
|
@ -9,41 +9,31 @@
|
||||||
|
|
||||||
import { useDispatch, useSelect } from '@wordpress/data';
|
import { useDispatch, useSelect } from '@wordpress/data';
|
||||||
import { useCallback } from '@wordpress/element';
|
import { useCallback } from '@wordpress/element';
|
||||||
|
|
||||||
|
import { createHooksForStore } from '../utils';
|
||||||
import { STORE_NAME } from './constants';
|
import { STORE_NAME } from './constants';
|
||||||
|
|
||||||
const useTransient = ( key ) =>
|
|
||||||
useSelect(
|
|
||||||
( select ) => select( STORE_NAME ).transientData()?.[ key ],
|
|
||||||
[ key ]
|
|
||||||
);
|
|
||||||
|
|
||||||
const usePersistent = ( key ) =>
|
|
||||||
useSelect(
|
|
||||||
( select ) => select( STORE_NAME ).persistentData()?.[ key ],
|
|
||||||
[ key ]
|
|
||||||
);
|
|
||||||
|
|
||||||
const useHooks = () => {
|
const useHooks = () => {
|
||||||
|
const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
|
||||||
const {
|
const {
|
||||||
persist,
|
persist,
|
||||||
setSandboxMode,
|
|
||||||
setManualConnectionMode,
|
|
||||||
sandboxOnboardingUrl,
|
sandboxOnboardingUrl,
|
||||||
productionOnboardingUrl,
|
productionOnboardingUrl,
|
||||||
authenticateWithCredentials,
|
authenticateWithCredentials,
|
||||||
authenticateWithOAuth,
|
authenticateWithOAuth,
|
||||||
setActiveModal,
|
|
||||||
startWebhookSimulation,
|
startWebhookSimulation,
|
||||||
checkWebhookSimulationState,
|
checkWebhookSimulationState,
|
||||||
} = useDispatch( STORE_NAME );
|
} = useDispatch( STORE_NAME );
|
||||||
|
|
||||||
// Transient accessors.
|
// Transient accessors.
|
||||||
const isReady = useTransient( 'isReady' );
|
const [ isReady ] = useTransient( 'isReady' );
|
||||||
const activeModal = useTransient( 'activeModal' );
|
const [ activeModal, setActiveModal ] = useTransient( 'activeModal' );
|
||||||
|
|
||||||
// Persistent accessors.
|
// Persistent accessors.
|
||||||
const isSandboxMode = usePersistent( 'useSandbox' );
|
const [ isSandboxMode, setSandboxMode ] = usePersistent( 'useSandbox' );
|
||||||
const isManualConnectionMode = usePersistent( 'useManualConnection' );
|
const [ isManualConnectionMode, setManualConnectionMode ] = usePersistent(
|
||||||
|
'useManualConnection'
|
||||||
|
);
|
||||||
const merchant = useSelect(
|
const merchant = useSelect(
|
||||||
( select ) => select( STORE_NAME ).merchant(),
|
( select ) => select( STORE_NAME ).merchant(),
|
||||||
[]
|
[]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue