Open andrewgordstewart opened 5 years ago
As Alex pointed out here, the following does not modify sharedData out side the scope of someModifier:
sharedData
someModifier
function someModifier(sharedData) { sharedData = {...sharedData, modified: true } } someModifier({ modified: false }) // does not modify `sharedData`
Therefore, we can avoid having to declare a new variable when we want to return a modified sharedData
function someModifier(sharedData) { newSharedData = {...sharedData, modified: true } return sharedData }
[Here])(https://github.com/magmo/apps/blob/master/packages/wallet/src/redux/protocols/concluding/instigator/reducer.ts#L122-L125) is an example of where this is performed.
We could instead do the following:
let updatedConsensusUpdateState: ConsensusUpdateState; ({ protocolState: updatedConsensusUpdateState, sharedData } = consensusUpdateReducer( protocolState.consensusUpdateState, sharedData, action, ));
This would prevent the type of bug where some reducer declares a side effect in its returned sharedData, but the parent reducer forgets to return sharedData: newSharedData.
sharedData: newSharedData
As Alex pointed out here, the following does not modify
sharedData
out side the scope ofsomeModifier
:Therefore, we can avoid having to declare a new variable when we want to return a modified
sharedData
[Here])(https://github.com/magmo/apps/blob/master/packages/wallet/src/redux/protocols/concluding/instigator/reducer.ts#L122-L125) is an example of where this is performed.
We could instead do the following:
This would prevent the type of bug where some reducer declares a side effect in its returned
sharedData
, but the parent reducer forgets to returnsharedData: newSharedData
.