♻️ Create isolated onboarding Redux store

This commit is contained in:
Philipp Stracker 2024-11-20 16:45:08 +01:00
parent 9e4d0c0819
commit 79174459d8
No known key found for this signature in database
5 changed files with 26 additions and 45 deletions

View file

@ -1,6 +1,4 @@
export const NAMESPACE = '/wc/v3/wc_paypal';
export const STORE_NAME = 'wc/paypal';
export const BUSINESS_TYPES = {
CASUAL_SELLER: 'casual_seller',
BUSINESS: 'business',

View file

@ -1,10 +1,9 @@
import { STORE_NAME } from './constants';
import { initStore } from './store';
import * as Onboarding from './onboarding';
import { addDebugTools } from './debug';
initStore();
Onboarding.initStore();
export const WC_PAYPAL_STORE_NAME = STORE_NAME;
export * from './onboarding/hooks';
export const OnboardingHooks = Onboarding.hooks;
export const OnboardingStoreName = Onboarding.STORE_NAME;
addDebugTools( window.ppcpSettings );

View file

@ -1,12 +1,11 @@
/**
* Name of the module-store in the main Redux store.
* Helps to isolate data.
* Name of the Redux store module.
*
* Used by: Reducer, Selector, Index
*
* @type {string}
*/
export const STORE_KEY = 'onboarding';
export const STORE_NAME = 'wc/paypal/onboarding';
/**
* REST path to hydrate data of this module by loading data from the WP DB..

View file

@ -1,8 +1,26 @@
import { STORE_KEY } from './constants';
import { createReduxStore, register } from '@wordpress/data';
import { controls as wpControls } from '@wordpress/data-controls';
import { STORE_NAME } from './constants';
import reducer from './reducer';
import * as selectors from './selectors';
import * as actions from './actions';
import * as resolvers from './resolvers';
import * as hooks from './hooks';
import { controls } from './controls';
export { reducer, selectors, actions, resolvers, controls, STORE_KEY };
export const initStore = () => {
const store = createReduxStore( STORE_NAME, {
reducer,
controls: { ...wpControls, ...controls },
actions,
selectors,
resolvers,
} );
register( store );
};
export { hooks };
export { STORE_NAME };

View file

@ -1,33 +0,0 @@
import { createReduxStore, register, combineReducers } from '@wordpress/data';
import { controls } from '@wordpress/data-controls';
import { STORE_NAME } from './constants';
// Import Redux modules.
import * as Onboarding from './onboarding';
const actions = {};
const selectors = {};
const resolvers = {};
[ Onboarding ].forEach( ( item ) => {
Object.assign( actions, { ...( item.actions || {} ) } );
Object.assign( selectors, { ...( item.selectors || {} ) } );
Object.assign( resolvers, { ...( item.resolvers || {} ) } );
Object.assign( controls, { ...( item.controls || {} ) } );
} );
const reducer = combineReducers( {
[ Onboarding.STORE_KEY ]: Onboarding.reducer,
} );
export const initStore = () => {
const store = createReduxStore( STORE_NAME, {
reducer,
controls,
actions,
selectors,
resolvers,
} );
register( store );
};