Skip to content

D3 directly manipulates given props #14

@alekseyl1992

Description

@alekseyl1992

Steps to reporoduce:

  1. Start example
  2. Set a breakpoint in onUpdateNode()
  3. Drag a node somewhere

Expected behaviour:
graph.nodes[i] === viewNode should evaluate to false
so that I have previous state and a new one to apply

Actual behaviour:
graph.nodes[i] === viewNode is true
which means, that D3 directly changed some parts of the state

First of all: this is discouraged by React documentation:
https://facebook.github.io/react/docs/react-component.html#state

Never mutate this.state directly, as calling setState() afterwards may replace the mutation you made. Treat this.state as if it were immutable.

And it actually means, that it's impossible to track changes history to provide Undo/Redo functionality.
Because there is no previous state available.

The easiest possible solution would be to just make a copy of state before passing it to the GraphView.
But it will break selection functionality. :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions