mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 16:15:43 +08:00
♻️ Create isolated onboarding Redux store
This commit is contained in:
parent
9e4d0c0819
commit
79174459d8
5 changed files with 26 additions and 45 deletions
|
@ -1,6 +1,4 @@
|
||||||
export const NAMESPACE = '/wc/v3/wc_paypal';
|
export const NAMESPACE = '/wc/v3/wc_paypal';
|
||||||
export const STORE_NAME = 'wc/paypal';
|
|
||||||
|
|
||||||
export const BUSINESS_TYPES = {
|
export const BUSINESS_TYPES = {
|
||||||
CASUAL_SELLER: 'casual_seller',
|
CASUAL_SELLER: 'casual_seller',
|
||||||
BUSINESS: 'business',
|
BUSINESS: 'business',
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import { STORE_NAME } from './constants';
|
import * as Onboarding from './onboarding';
|
||||||
import { initStore } from './store';
|
|
||||||
import { addDebugTools } from './debug';
|
import { addDebugTools } from './debug';
|
||||||
|
|
||||||
initStore();
|
Onboarding.initStore();
|
||||||
|
|
||||||
export const WC_PAYPAL_STORE_NAME = STORE_NAME;
|
export const OnboardingHooks = Onboarding.hooks;
|
||||||
export * from './onboarding/hooks';
|
export const OnboardingStoreName = Onboarding.STORE_NAME;
|
||||||
|
|
||||||
addDebugTools( window.ppcpSettings );
|
addDebugTools( window.ppcpSettings );
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
/**
|
/**
|
||||||
* Name of the module-store in the main Redux store.
|
* Name of the Redux store module.
|
||||||
* Helps to isolate data.
|
|
||||||
*
|
*
|
||||||
* Used by: Reducer, Selector, Index
|
* Used by: Reducer, Selector, Index
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @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..
|
* REST path to hydrate data of this module by loading data from the WP DB..
|
||||||
|
|
|
@ -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 reducer from './reducer';
|
||||||
import * as selectors from './selectors';
|
import * as selectors from './selectors';
|
||||||
import * as actions from './actions';
|
import * as actions from './actions';
|
||||||
import * as resolvers from './resolvers';
|
import * as resolvers from './resolvers';
|
||||||
|
import * as hooks from './hooks';
|
||||||
import { controls } from './controls';
|
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 };
|
||||||
|
|
|
@ -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 );
|
|
||||||
};
|
|
Loading…
Add table
Add a link
Reference in a new issue