♻️ 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.
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.

View file

@ -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;