Fix #917, #926: update ordering of object keys

This commit is contained in:
jos 2020-03-18 10:44:25 +01:00
parent 3363c2df8a
commit b09dbca3fd
2 changed files with 9 additions and 24 deletions

View File

@ -4,7 +4,7 @@ https://github.com/josdejong/jsoneditor
## not yet published, version 8.6.2
- Fixed #926: Keep order of properties when updating an object.
- Fixed #917, #926: Keep order of properties when updating an object.
- Fixed #928: Custom root name not reflected in path of navigation bar.
- Upgraded to `ajv@6.12.0`

View File

@ -1490,31 +1490,16 @@ export class Node {
return false
}
// TODO: for better efficiency, we could create a property `isDuplicate` on all of the childs
// and keep that up to date. This should make deepEqual about 20% faster.
const props = {}
let propCount = 0
for (i = 0; i < this.childs.length; i++) {
const child = this.childs[i]
if (!props[child.field]) {
// We can have childs with duplicate field names.
// We take the first, and ignore the others.
props[child.field] = true
propCount++
if (!(child.field in json)) {
// we reckon with the order of the properties too.
const props = Object.keys(json)
if (this.childs.length !== props.length) {
return false
}
if (!child.deepEqual(json[child.field])) {
for (i = 0; i < props.length; i++) {
if (this.childs[i].field !== props[i]) {
return false
}
}
}
if (propCount !== Object.keys(json).length) {
return false
}
} else {
if (this.value !== json) {
return false