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 { resolvers } from './resolvers';
|
||||||
import { controls } from './controls';
|
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 = () => {
|
export const initStore = () => {
|
||||||
const store = createReduxStore( STORE_NAME, {
|
const store = createReduxStore( STORE_NAME, {
|
||||||
reducer,
|
reducer,
|
||||||
|
@ -19,6 +25,8 @@ export const initStore = () => {
|
||||||
} );
|
} );
|
||||||
|
|
||||||
register( store );
|
register( store );
|
||||||
|
|
||||||
|
return Boolean( wp.data.select( STORE_NAME ) );
|
||||||
};
|
};
|
||||||
|
|
||||||
export { hooks, selectors, STORE_NAME };
|
export { hooks, selectors, STORE_NAME };
|
||||||
|
|
|
@ -9,6 +9,12 @@ import * as hooks from './hooks';
|
||||||
import { resolvers } from './resolvers';
|
import { resolvers } from './resolvers';
|
||||||
import { controls } from './controls';
|
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 = () => {
|
export const initStore = () => {
|
||||||
const store = createReduxStore( STORE_NAME, {
|
const store = createReduxStore( STORE_NAME, {
|
||||||
reducer,
|
reducer,
|
||||||
|
@ -19,6 +25,8 @@ export const initStore = () => {
|
||||||
} );
|
} );
|
||||||
|
|
||||||
register( store );
|
register( store );
|
||||||
|
|
||||||
|
return Boolean( wp.data.select( STORE_NAME ) );
|
||||||
};
|
};
|
||||||
|
|
||||||
export { hooks, selectors, STORE_NAME };
|
export { hooks, selectors, STORE_NAME };
|
||||||
|
|
|
@ -5,11 +5,23 @@ import * as Payment from './payment';
|
||||||
import * as Settings from './settings-tab';
|
import * as Settings from './settings-tab';
|
||||||
import * as Styling from './styling';
|
import * as Styling from './styling';
|
||||||
|
|
||||||
Onboarding.initStore();
|
const stores = [ Onboarding, Common, Payment, Settings, Styling ];
|
||||||
Common.initStore();
|
|
||||||
Payment.initStore();
|
stores.forEach( ( store ) => {
|
||||||
Settings.initStore();
|
try {
|
||||||
Styling.initStore();
|
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 OnboardingHooks = Onboarding.hooks;
|
||||||
export const CommonHooks = Common.hooks;
|
export const CommonHooks = Common.hooks;
|
||||||
|
@ -25,10 +37,4 @@ export const StylingStoreName = Styling.STORE_NAME;
|
||||||
|
|
||||||
export * from './configuration';
|
export * from './configuration';
|
||||||
|
|
||||||
addDebugTools( window.ppcpSettings, [
|
addDebugTools( window.ppcpSettings, stores );
|
||||||
Onboarding,
|
|
||||||
Common,
|
|
||||||
Payment,
|
|
||||||
Settings,
|
|
||||||
Styling,
|
|
||||||
] );
|
|
||||||
|
|
|
@ -9,6 +9,12 @@ import * as hooks from './hooks';
|
||||||
import { resolvers } from './resolvers';
|
import { resolvers } from './resolvers';
|
||||||
import { controls } from './controls';
|
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 = () => {
|
export const initStore = () => {
|
||||||
const store = createReduxStore( STORE_NAME, {
|
const store = createReduxStore( STORE_NAME, {
|
||||||
reducer,
|
reducer,
|
||||||
|
@ -19,6 +25,8 @@ export const initStore = () => {
|
||||||
} );
|
} );
|
||||||
|
|
||||||
register( store );
|
register( store );
|
||||||
|
|
||||||
|
return Boolean( wp.data.select( STORE_NAME ) );
|
||||||
};
|
};
|
||||||
|
|
||||||
export { hooks, selectors, STORE_NAME };
|
export { hooks, selectors, STORE_NAME };
|
||||||
|
|
|
@ -9,6 +9,12 @@ import * as hooks from './hooks';
|
||||||
import { resolvers } from './resolvers';
|
import { resolvers } from './resolvers';
|
||||||
import { controls } from './controls';
|
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 = () => {
|
export const initStore = () => {
|
||||||
const store = createReduxStore( STORE_NAME, {
|
const store = createReduxStore( STORE_NAME, {
|
||||||
reducer,
|
reducer,
|
||||||
|
@ -19,6 +25,8 @@ export const initStore = () => {
|
||||||
} );
|
} );
|
||||||
|
|
||||||
register( store );
|
register( store );
|
||||||
|
|
||||||
|
return Boolean( wp.data.select( STORE_NAME ) );
|
||||||
};
|
};
|
||||||
|
|
||||||
export { hooks, selectors, STORE_NAME };
|
export { hooks, selectors, STORE_NAME };
|
||||||
|
|
|
@ -25,28 +25,16 @@ import { controls } from './controls';
|
||||||
* @return {boolean} True if initialization succeeded, false otherwise.
|
* @return {boolean} True if initialization succeeded, false otherwise.
|
||||||
*/
|
*/
|
||||||
export const initStore = () => {
|
export const initStore = () => {
|
||||||
try {
|
const store = createReduxStore( STORE_NAME, {
|
||||||
const store = createReduxStore( STORE_NAME, {
|
reducer,
|
||||||
reducer,
|
controls: { ...wpControls, ...controls },
|
||||||
controls: { ...wpControls, ...controls },
|
actions,
|
||||||
actions,
|
selectors,
|
||||||
selectors,
|
resolvers,
|
||||||
resolvers,
|
} );
|
||||||
} );
|
register( store );
|
||||||
register( store );
|
|
||||||
|
|
||||||
// Verify store registration
|
return Boolean( wp.data.select( STORE_NAME ) );
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export { hooks, selectors, STORE_NAME };
|
export { hooks, selectors, STORE_NAME };
|
||||||
|
|
|
@ -9,6 +9,12 @@ import * as hooks from './hooks';
|
||||||
import { resolvers } from './resolvers';
|
import { resolvers } from './resolvers';
|
||||||
import { controls } from './controls';
|
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 = () => {
|
export const initStore = () => {
|
||||||
const store = createReduxStore( STORE_NAME, {
|
const store = createReduxStore( STORE_NAME, {
|
||||||
reducer,
|
reducer,
|
||||||
|
@ -19,6 +25,8 @@ export const initStore = () => {
|
||||||
} );
|
} );
|
||||||
|
|
||||||
register( store );
|
register( store );
|
||||||
|
|
||||||
|
return Boolean( wp.data.select( STORE_NAME ) );
|
||||||
};
|
};
|
||||||
|
|
||||||
export { hooks, selectors, STORE_NAME };
|
export { hooks, selectors, STORE_NAME };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue