Skip to content

Enhancement Request: Add support for 'upserting' values #2

@dcwangmit01

Description

@dcwangmit01

The current code is able to change values for selector paths which already exist in the obj. It would be nice if there were support for 'upsert' which would update a field if the selector path already exists, OR add a field and selector path if the path does not exist.

This following works, because the selector path ["a", "b"] already exists in the 'obj' {a: {b: "before"}.

m.change(["a", "b"], "after")({a: {b: "before"})

The result is:

{"a": {"b": "after"}}

It would be nice if

m.upsert(["a", "b"], "after")({}) // Note the empty obj({})

Would produce the same result as above, even though the selector path ["a", "b"] does not exist in the obj {}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions