mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
✨ Consistent storeInit and error handling logic
This commit is contained in:
parent
2818fd5d76
commit
7fad70d6e5
7 changed files with 67 additions and 33 deletions
|
@ -9,6 +9,12 @@ import * as hooks from './hooks';
|
|||
import { resolvers } from './resolvers';
|
||||
import { controls } from './controls';
|
||||
|
||||
/**
|
||||
* Initializes and registers the settings store with WordPress data layer.
|
||||
* Combines custom controls with WordPress data controls.
|
||||
*
|
||||
* @return {boolean} True if initialization succeeded, false otherwise.
|
||||
*/
|
||||
export const initStore = () => {
|
||||
const store = createReduxStore( STORE_NAME, {
|
||||
reducer,
|
||||
|
@ -19,6 +25,8 @@ export const initStore = () => {
|
|||
} );
|
||||
|
||||
register( store );
|
||||
|
||||
return Boolean( wp.data.select( STORE_NAME ) );
|
||||
};
|
||||
|
||||
export { hooks, selectors, STORE_NAME };
|
||||
|
|
|
@ -9,6 +9,12 @@ import * as hooks from './hooks';
|
|||
import { resolvers } from './resolvers';
|
||||
import { controls } from './controls';
|
||||
|
||||
/**
|
||||
* Initializes and registers the settings store with WordPress data layer.
|
||||
* Combines custom controls with WordPress data controls.
|
||||
*
|
||||
* @return {boolean} True if initialization succeeded, false otherwise.
|
||||
*/
|
||||
export const initStore = () => {
|
||||
const store = createReduxStore( STORE_NAME, {
|
||||
reducer,
|
||||
|
@ -19,6 +25,8 @@ export const initStore = () => {
|
|||
} );
|
||||
|
||||
register( store );
|
||||
|
||||
return Boolean( wp.data.select( STORE_NAME ) );
|
||||
};
|
||||
|
||||
export { hooks, selectors, STORE_NAME };
|
||||
|
|
|
@ -5,11 +5,23 @@ import * as Payment from './payment';
|
|||
import * as Settings from './settings-tab';
|
||||
import * as Styling from './styling';
|
||||
|
||||
Onboarding.initStore();
|
||||
Common.initStore();
|
||||
Payment.initStore();
|
||||
Settings.initStore();
|
||||
Styling.initStore();
|
||||
const stores = [ Onboarding, Common, Payment, Settings, Styling ];
|
||||
|
||||
stores.forEach( ( store ) => {
|
||||
try {
|
||||
if ( false === store.initStore() ) {
|
||||
console.error(
|
||||
`Store initialization failed for ${ store.STORE_NAME }`
|
||||
);
|
||||
}
|
||||
} catch ( e ) {
|
||||
console.error(
|
||||
'Error during store initialization:',
|
||||
store.STORE_NAME,
|
||||
e
|
||||
);
|
||||
}
|
||||
} );
|
||||
|
||||
export const OnboardingHooks = Onboarding.hooks;
|
||||
export const CommonHooks = Common.hooks;
|
||||
|
@ -25,10 +37,4 @@ export const StylingStoreName = Styling.STORE_NAME;
|
|||
|
||||
export * from './configuration';
|
||||
|
||||
addDebugTools( window.ppcpSettings, [
|
||||
Onboarding,
|
||||
Common,
|
||||
Payment,
|
||||
Settings,
|
||||
Styling,
|
||||
] );
|
||||
addDebugTools( window.ppcpSettings, stores );
|
||||
|
|
|
@ -9,6 +9,12 @@ import * as hooks from './hooks';
|
|||
import { resolvers } from './resolvers';
|
||||
import { controls } from './controls';
|
||||
|
||||
/**
|
||||
* Initializes and registers the settings store with WordPress data layer.
|
||||
* Combines custom controls with WordPress data controls.
|
||||
*
|
||||
* @return {boolean} True if initialization succeeded, false otherwise.
|
||||
*/
|
||||
export const initStore = () => {
|
||||
const store = createReduxStore( STORE_NAME, {
|
||||
reducer,
|
||||
|
@ -19,6 +25,8 @@ export const initStore = () => {
|
|||
} );
|
||||
|
||||
register( store );
|
||||
|
||||
return Boolean( wp.data.select( STORE_NAME ) );
|
||||
};
|
||||
|
||||
export { hooks, selectors, STORE_NAME };
|
||||
|
|
|
@ -9,6 +9,12 @@ import * as hooks from './hooks';
|
|||
import { resolvers } from './resolvers';
|
||||
import { controls } from './controls';
|
||||
|
||||
/**
|
||||
* Initializes and registers the settings store with WordPress data layer.
|
||||
* Combines custom controls with WordPress data controls.
|
||||
*
|
||||
* @return {boolean} True if initialization succeeded, false otherwise.
|
||||
*/
|
||||
export const initStore = () => {
|
||||
const store = createReduxStore( STORE_NAME, {
|
||||
reducer,
|
||||
|
@ -19,6 +25,8 @@ export const initStore = () => {
|
|||
} );
|
||||
|
||||
register( store );
|
||||
|
||||
return Boolean( wp.data.select( STORE_NAME ) );
|
||||
};
|
||||
|
||||
export { hooks, selectors, STORE_NAME };
|
||||
|
|
|
@ -25,7 +25,6 @@ import { controls } from './controls';
|
|||
* @return {boolean} True if initialization succeeded, false otherwise.
|
||||
*/
|
||||
export const initStore = () => {
|
||||
try {
|
||||
const store = createReduxStore( STORE_NAME, {
|
||||
reducer,
|
||||
controls: { ...wpControls, ...controls },
|
||||
|
@ -35,18 +34,7 @@ export const initStore = () => {
|
|||
} );
|
||||
register( store );
|
||||
|
||||
// Verify store registration
|
||||
const isStoreRegistered = Boolean( wp.data.select( STORE_NAME ) );
|
||||
if ( ! isStoreRegistered ) {
|
||||
console.error( 'Store registration verification failed' );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch ( error ) {
|
||||
console.error( 'Failed to initialize settings store:', error );
|
||||
return false;
|
||||
}
|
||||
return Boolean( wp.data.select( STORE_NAME ) );
|
||||
};
|
||||
|
||||
export { hooks, selectors, STORE_NAME };
|
||||
|
|
|
@ -9,6 +9,12 @@ import * as hooks from './hooks';
|
|||
import { resolvers } from './resolvers';
|
||||
import { controls } from './controls';
|
||||
|
||||
/**
|
||||
* Initializes and registers the settings store with WordPress data layer.
|
||||
* Combines custom controls with WordPress data controls.
|
||||
*
|
||||
* @return {boolean} True if initialization succeeded, false otherwise.
|
||||
*/
|
||||
export const initStore = () => {
|
||||
const store = createReduxStore( STORE_NAME, {
|
||||
reducer,
|
||||
|
@ -19,6 +25,8 @@ export const initStore = () => {
|
|||
} );
|
||||
|
||||
register( store );
|
||||
|
||||
return Boolean( wp.data.select( STORE_NAME ) );
|
||||
};
|
||||
|
||||
export { hooks, selectors, STORE_NAME };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue