-
Notifications
You must be signed in to change notification settings - Fork 265
Description
Steps to reporoduce:
- Start example
- Set a breakpoint in
onUpdateNode() - 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. :(