Skip to content

Commit

Permalink
Refactor splice method.
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinRixham committed Nov 19, 2016
1 parent da5eb29 commit 7823a8c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/array/ArrayElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ define(["array/ArrayItemElement"], function(ArrayItemElement) {
element.insertBefore(child.clone(), element.firstChild);
};

this.insertAtIndex = function(index) {

element.insertBefore(child.clone(), element.children[index]);
};

this.removeFirst = function() {

if (element.firstElementChild) {
Expand All @@ -62,6 +67,11 @@ define(["array/ArrayItemElement"], function(ArrayItemElement) {
}
};

this.removeAtIndex = function(index) {

element.removeChild(element.children[index]);
};

this.removeChildren = function() {

var children = [].slice.call(element.children);
Expand Down
11 changes: 5 additions & 6 deletions src/array/method/Splice.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ define([

for (var i = 0; i < elements.length; i++) {

var element = elements[i].get();
var element = elements[i];
var end = Math.min(start + deleteCount, model.length) - 1;

for (var j = end; j >= start; j--) {

element.removeChild(element.children[j]);
element.removeAtIndex(j);
}

properties.splice(start, deleteCount);
Expand All @@ -60,11 +60,10 @@ define([

for (var j = 0; j < elements.length; j++) {

var element = elements[j].get();
var child = elements[j].getChild();
var element = elements[j];

element.insertBefore(child.clone(), element.children[start]);
property.applyBinding(new DOMElement(element), start, model);
element.insertAtIndex(start);
property.applyBinding(new DOMElement(element.get()), start, model);
}
}
}
Expand Down

0 comments on commit 7823a8c

Please sign in to comment.