PlotlyEditor handleUpdate mutates inputs instead of following unidirectional data flow
See original GitHub issueDue to the way the editor is wired to depend on the graphDiv
DOM element from react-plotly.js
, handleUpdate
is mutating the data
/layout
, and then uses onUpdate
as a “something changed” flag. So, it’s essentially just bypassing the React render loop altogether by flowing some data mutations directly back to the embedded Plotly inside react-plotly.js
.
What it should be doing is using something like immutability-helper
to create an updated immutable copy of data
/layout
, and then send back those changes out as values to the onUpdate
callback. The callback would then update the higher state, and those new changes would flow back down into the data
& layout
props of both the Plot
and PlotlyEditor
components.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Master React Unidirectional Data Flow
Understanding React unidirectional data flow is integral to scaffolding scalable applications.
Read more >Unidirectional data flow in React
I've made the following snippets to sense the essential difference, then it seems that the unidirectional mandates the application to propagate ...
Read more >Why does React emphasize on unidirectional data flow ...
Unidirectional data flow is a technique found in functional reactive programming. ... Also an input field in the view can mutate your model....
Read more >Unidirectional Data flow in React
What is Unidirectional Data Flow? React is a library that allows developers to build reusable components and insist on one-way data flow.
Read more >Unidirectional Data Flow - Two Ways
I needed to modify the model slightly so I could take inputs using US Customary Units rather than SI Units. The end result...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m definitely not dismissing immutability, I’m working hard to promote it and we’re making changes to plotly.js to use it! 😃
That said, copying large arrays is much slower than “not exactly the same” … Per https://jsperf.com/copy-large-array/1 for me the slice-and-push operation runs at ~60 ops/sec and the push-only runs at ~30,000,000 ops/sec.
Once #384 settles down, it will be easier to resolve this (and #212, which was already intended to do this!) as per https://github.com/plotly/react-chart-editor/pull/384#discussion_r172730087