Skip to content

Discussion: Immutable chart actions #31

Open
@eran-pinhas

Description

Currently the actions are changing the chart object.

From my experience in react it's better to clone the state object than change the object itself for various reasons (for react to know when to update the DOM without deep comparison with previous state)

For example: in actions.ts:

if (chart.selected.id !== nodeId || chart.selected.type !== 'node') {
  chart.selected = {
    type: 'node',
    id: nodeId,
  }
}
return chart

Would be immutable as:

 if (chart.selected.id !== nodeId || chart.selected.type !== "node") {
   return {
     ...chart,
     selected: {
       type: "node",
       id: nodeId
     }
   };
 }
 else return chart;

@MrBlenny What do you think?

Activity

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions