Skip to content

Immutable mode for nestedProperty #2418

Closed
@vdh

Description

@vdh

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.

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