Skip to content

Order changed by updateIn #48

Description

@jeff303

Consider the following snippet, run against Icepick 2.4.0:

var icepick = require("icepick")

const BEFORE = {
  first: {
    name: "First",
    items: [{key: "first-a", value: 12}]
  },
  second: {
    name: "Second",
    items: [{key: "second-a", value: 13}]
  },
  third: {
    name: "Third",
    items: [{key: "third-a", value: 15}]
  }
};

console.log(BEFORE);

const AFTER = icepick.updateIn(BEFORE, ["second", "items"], items => [
  ...items,
  {
    key: "second-x",
    value: 42
  },
]);

console.log(AFTER);

In this case, the output is:

Object
first: Object {name: "First", items: [Object {key: "first-a", value: 12}]}
second: Object {name: "Second", items: [Object {key: "second-a", value: 13}]}
third: Object {name: "Third", items: [Object {key: "third-a", value: 15}]}

Object
third: Object {name: "Third", items: [Object {key: "third-a", value: 15}]}
second: Object {items: [Object {key: "second-a", value: 13}, Object {key: "second-x", value: 42}], name: "Second"}
first: Object {name: "First", items: [Object {key: "first-a", value: 12}]}

Notice that the order of keys has been reversed by this operation (where an item was added to the items collection of the 2nd value in the map). I realize that maps are inherently unordered, but it might still be useful if this operation didn't change the order.

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