Skip to content

Instantly share code, notes, and snippets.

@blockiyt
Created January 30, 2023 09:23
Show Gist options
  • Save blockiyt/0e37ca606ec232b38599d271d6aacdd9 to your computer and use it in GitHub Desktop.
Save blockiyt/0e37ca606ec232b38599d271d6aacdd9 to your computer and use it in GitHub Desktop.
Code for Issue
const before = [
{
"classes": [
"5C"
],
"period": 3,
"new-teacher": "Hans",
"old-teacher": "Peter",
"new-subject": {
"short": "Mu",
"full": "Musik"
},
"old-subject": {
"short": "E",
"full": "Englisch"
},
"room": "Mu2",
"description": null
},
{
"classes": [
"5D"
],
"period": 3,
"new-teacher": "Karl",
"old-teacher": "Gustaf",
"new-subject": {
"short": "M",
"full": "Mathematik"
},
"old-subject": {
"short": "M",
"full": "Mathematik"
},
"room": "1.018",
"description": null
}
]
const after = [
{
"classes": [
"5C"
],
"period": 3,
"new-teacher": "Hans",
"old-teacher": "Peter",
"new-subject": {
"short": "Mu",
"full": "Musik"
},
"old-subject": {
"short": "E",
"full": "Englisch"
},
"room": "Mu2",
"description": null
}
]
const diffs = detailedDiff(before, after)
//expected:
/*
> {
> added: [Object: null prototype] {},
> deleted: [Object: null prototype] {
> '1': undefined
> },
> updated: [Object: null prototype] {}
> }
*/
//what acctually happens:
//because something from the array got removed, the indices of every entry are changing and that's registered as updated
/*
> {
> added: [Object: null prototype] {},
> deleted: [Object: null prototype] {},
> updated: [Object: null prototype] {
> '0': [Object: null prototype] {
> 'new-teacher': 'Karl',
> period: 3,
> 'new-subject': [Object: null prototype],
> classes: [Object: null prototype],
> 'old-subject': [Object: null prototype],
> description: null,
> 'old-teacher': 'Gustaf',
> room: '1.018'
> }
}
> }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment