mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +08:00
♻️ Minor: Freeze read-only state objects
This commit is contained in:
parent
82b364a0ac
commit
2b2d5585b1
2 changed files with 18 additions and 15 deletions
|
@ -12,30 +12,30 @@ import ACTION_TYPES from './action-types';
|
|||
|
||||
// Store structure.
|
||||
|
||||
const defaultTransient = {
|
||||
const defaultTransient = Object.freeze( {
|
||||
isReady: false,
|
||||
activities: new Map(),
|
||||
|
||||
// Read only values, provided by the server via hydrate.
|
||||
merchant: {
|
||||
merchant: Object.freeze( {
|
||||
isConnected: false,
|
||||
isSandbox: false,
|
||||
id: '',
|
||||
email: '',
|
||||
},
|
||||
} ),
|
||||
|
||||
wooSettings: {
|
||||
wooSettings: Object.freeze( {
|
||||
storeCountry: '',
|
||||
storeCurrency: '',
|
||||
},
|
||||
};
|
||||
} ),
|
||||
} );
|
||||
|
||||
const defaultPersistent = {
|
||||
const defaultPersistent = Object.freeze( {
|
||||
useSandbox: false,
|
||||
useManualConnection: false,
|
||||
clientId: '',
|
||||
clientSecret: '',
|
||||
};
|
||||
} );
|
||||
|
||||
// Reducer logic.
|
||||
|
||||
|
|
|
@ -12,24 +12,24 @@ import ACTION_TYPES from './action-types';
|
|||
|
||||
// Store structure.
|
||||
|
||||
const defaultTransient = {
|
||||
const defaultTransient = Object.freeze( {
|
||||
isReady: false,
|
||||
|
||||
// Read only values, provided by the server.
|
||||
flags: {
|
||||
flags: Object.freeze( {
|
||||
canUseCasualSelling: false,
|
||||
canUseVaulting: false,
|
||||
canUseCardPayments: false,
|
||||
},
|
||||
};
|
||||
} ),
|
||||
} );
|
||||
|
||||
const defaultPersistent = {
|
||||
const defaultPersistent = Object.freeze( {
|
||||
completed: false,
|
||||
step: 0,
|
||||
isCasualSeller: null, // null value will uncheck both options in the UI.
|
||||
areOptionalPaymentMethodsEnabled: null,
|
||||
products: [],
|
||||
};
|
||||
} );
|
||||
|
||||
// Reducer logic.
|
||||
|
||||
|
@ -63,7 +63,10 @@ const onboardingReducer = createReducer( defaultTransient, defaultPersistent, {
|
|||
|
||||
// Flags are not updated by `setPersistent()`.
|
||||
if ( payload.flags ) {
|
||||
newState.flags = { ...newState.flags, ...payload.flags };
|
||||
newState.flags = Object.freeze( {
|
||||
...newState.flags,
|
||||
...payload.flags,
|
||||
} );
|
||||
}
|
||||
|
||||
return newState;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue