Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

sharedData = someModifier(sharedData) #627

Description

@andrewgordstewart

As Alex pointed out here, the following does not modify sharedData out side the scope of 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions