hadron-document
Advanced tools
Comparing version 3.1.3 to 3.1.4
@@ -232,2 +232,5 @@ 'use strict'; | ||
if (this.currentType === 'Array') { | ||
if (element.currentKey === '') { | ||
this.elements.handleEmptyKeys(element); | ||
} | ||
key = element.currentKey + 1; | ||
@@ -253,3 +256,9 @@ } | ||
if (this.currentType === 'Array') { | ||
key = this.elements.lastElement ? this.elements.lastElement.currentKey + 1 : 0; | ||
key = 0; | ||
if (this.elements.lastElement) { | ||
if (this.elements.lastElement.currentKey === '') { | ||
this.elements.handleEmptyKeys(this.elements.lastElement); | ||
} | ||
key = this.elements.lastElement.currentKey + 1; | ||
} | ||
} | ||
@@ -267,7 +276,5 @@ var newElement = this.elements.insertEnd(key, value, true, this); | ||
insertPlaceholder() { | ||
let key = ''; | ||
if (this.currentType === 'Array') { | ||
key = this.elements.lastElement ? this.elements.lastElement.currentKey + 1 : 0; | ||
} | ||
return this.insertEnd(key, ''); | ||
var newElement = this.elements.insertEnd('', '', true, this); | ||
this._bubbleUp(Events.Added); | ||
return newElement; | ||
} | ||
@@ -718,2 +725,26 @@ | ||
/** | ||
* If an element is added after a placeholder, convert that placeholder | ||
* into an empty element with the correct key. | ||
* | ||
* @param {Element} element - The placeholder element. | ||
*/ | ||
handleEmptyKeys(element) { | ||
if (element.currentKey === '') { | ||
let e = element; | ||
while (e.currentKey === '') { | ||
if (!e.previousElement) { | ||
e.currentKey = 0; | ||
break; | ||
} else { | ||
e = e.previousElement; | ||
} | ||
} | ||
while (e.nextElement) { | ||
e.nextElement.currentKey = e.currentKey + 1; | ||
e = e.nextElement; | ||
} | ||
} | ||
} | ||
/** | ||
* Insert data before the provided element. | ||
@@ -720,0 +751,0 @@ * |
@@ -7,3 +7,3 @@ { | ||
"homepage": "https://github.com/mongodb-js/hadron-document", | ||
"version": "3.1.3", | ||
"version": "3.1.4", | ||
"repository": { | ||
@@ -10,0 +10,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
140489
1065