UNPKG

ecl

Version:

Evented Components Library

44 lines (37 loc) 1.06 kB
var Node, extend = require("extends__"), hasProp = {}.hasOwnProperty; module.exports = Node = (function(superClass) { extend(Node, superClass); function Node() { Node.__super__.constructor.apply(this, arguments); } Node.prototype.appendChild = function(child) { var ref; if (child !== this) { this.children || (this.children = []); if (-1 === this.children.indexOf(child)) { if ((ref = child.parent) != null) { if (typeof ref.removeChild === "function") { ref.removeChild(child); } } child.parent = this; this.children.push(child); } } return this; }; Node.prototype.removeChild = function(child) { var idx, ref; if (((ref = this.children) != null ? ref.length : void 0) && -1 !== (idx = this.children.indexOf(child))) { delete child.parent; this.children.splice(idx, 1); if (this.children.length === 0) { delete this.children; } } return this; }; return Node; })(require('./base'));