♻️ Minor: Freeze read-only state objects

This commit is contained in:
Philipp Stracker 2024-12-06 19:22:32 +01:00
parent 82b364a0ac
commit 2b2d5585b1
No known key found for this signature in database
2 changed files with 18 additions and 15 deletions

View file

@ -12,30 +12,30 @@ import ACTION_TYPES from './action-types';
// Store structure. // Store structure.
const defaultTransient = { const defaultTransient = Object.freeze( {
isReady: false, isReady: false,
activities: new Map(), activities: new Map(),
// Read only values, provided by the server via hydrate. // Read only values, provided by the server via hydrate.
merchant: { merchant: Object.freeze( {
isConnected: false, isConnected: false,
isSandbox: false, isSandbox: false,
id: '', id: '',
email: '', email: '',
}, } ),
wooSettings: { wooSettings: Object.freeze( {
storeCountry: '', storeCountry: '',
storeCurrency: '', storeCurrency: '',
}, } ),
}; } );
const defaultPersistent = { const defaultPersistent = Object.freeze( {
useSandbox: false, useSandbox: false,
useManualConnection: false, useManualConnection: false,
clientId: '', clientId: '',
clientSecret: '', clientSecret: '',
}; } );
// Reducer logic. // Reducer logic.

View file

@ -12,24 +12,24 @@ import ACTION_TYPES from './action-types';
// Store structure. // Store structure.
const defaultTransient = { const defaultTransient = Object.freeze( {
isReady: false, isReady: false,
// Read only values, provided by the server. // Read only values, provided by the server.
flags: { flags: Object.freeze( {
canUseCasualSelling: false, canUseCasualSelling: false,
canUseVaulting: false, canUseVaulting: false,
canUseCardPayments: false, canUseCardPayments: false,
}, } ),
}; } );
const defaultPersistent = { const defaultPersistent = Object.freeze( {
completed: false, completed: false,
step: 0, step: 0,
isCasualSeller: null, // null value will uncheck both options in the UI. isCasualSeller: null, // null value will uncheck both options in the UI.
areOptionalPaymentMethodsEnabled: null, areOptionalPaymentMethodsEnabled: null,
products: [], products: [],
}; } );
// Reducer logic. // Reducer logic.
@ -63,7 +63,10 @@ const onboardingReducer = createReducer( defaultTransient, defaultPersistent, {
// Flags are not updated by `setPersistent()`. // Flags are not updated by `setPersistent()`.
if ( payload.flags ) { if ( payload.flags ) {
newState.flags = { ...newState.flags, ...payload.flags }; newState.flags = Object.freeze( {
...newState.flags,
...payload.flags,
} );
} }
return newState; return newState;