Description
Related to the immutable mode idea: #2389
While exploring an immutable mode solution for react-plotly-js-editor
, I noticed a dependency upon Plotly's nestedProperty
.
What would be the most ideal way to make an immutable alternative for nestedProperty
?
In a generic scenario the dependency is:
const prop = nestedProperty(container, attr);
prop.set(value); // container is mutated
And an alternative immutable API in nestedProperty
could do this instead:
const prop = nestedProperty(container, attr);
const newContainer = prop.setImmutable(value);
Where setImmutable
is the same logic as set
(npSet
), but returns an updated copy of the container instead. Under the hood it would use something like immutability-helper
to reuse unchanged data when copying.
Or would it perhaps be better to create an alternative library file? For example:
const newContainer = nestedPropertySetImmutable(container, attr, value);
Which would be an immutable conversion of npSet
(using immutability-helper
). The downside of this approach is that it might create a code fork between it and nestedProperty
.