Skip to content

Commit

Permalink
Merge pull request #1 from heff/review-erikyuzwa-feature/add-child-wi…
Browse files Browse the repository at this point in the history
…th-index

Minor changes to #2540
  • Loading branch information
erikyuzwa committed Sep 2, 2015
2 parents 80d8f26 + ba0065a commit 19cad93
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/js/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class Component {
* @return {Component} The child component (created by this process if a string was used)
* @method addChild
*/
addChild(child, options={}, index='undefined') {
addChild(child, options={}, index=this.children_.length) {
let component;
let componentName;

Expand Down Expand Up @@ -380,11 +380,7 @@ class Component {
component = child;
}

if (typeof index === 'number') {
this.children_.splice(index, 0, component);
} else {
this.children_.push(component);
}
this.children_.splice(index, 0, component);

if (typeof component.id === 'function') {
this.childIndex_[component.id()] = component;
Expand All @@ -401,7 +397,7 @@ class Component {
// Add the UI object's element to the container div (box)
// Having an element is not required
if (typeof component.el === 'function' && component.el()) {
this.contentEl().appendChild(component.el());
this.contentEl().insertBefore(component.el(), this.contentEl().children[index]);
}

// Return so it can stored on parent object if desired.
Expand Down

0 comments on commit 19cad93

Please sign in to comment.