Skip to content

Array with objects causes weird (broken) patches #42

@FrittenKeeZ

Description

@FrittenKeeZ

Comparing arrays with simple objects results in a weird broken patch.

import { diff } from 'jiff'

const $old = [{ id: 1 }]
const $new = [{ id: 2 }]
const $patch = diff($old, $new)
console.log($patch)

Expected outcome:

[
  { op: "test", path: "/0/id", value: 1 },
  { op: "replace", path: "/0/id", value: 2 },
]

Actual outcome:

[
  { op: "add", path: "/0", value: { id: 2 } },
  { op: "test", path: "/1", value: { id: 1 } },
  { op: "remove", path: "/1" },
]

I tried with a custom hasher method from another issue, but this didn't help.

Update: I switched to https://github.com/Starcounter-Jack/JSON-Patch which does exactly what I expected above.

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