Comparing version 0.2.2 to 0.2.3
@@ -142,3 +142,3 @@ (function (global, factory) { | ||
for (var i = 0, _length3 = this.children.length; i < _length3; i++) { | ||
callback(this.children[i]); | ||
this.children[i].forEach(callback); | ||
} | ||
@@ -145,0 +145,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(e,n){if("function"==typeof define&&define.amd)define(["exports"],n);else if("undefined"!=typeof exports)n(exports);else{var t={exports:{}};n(t.exports),e.treenode=t.exports}}(this,function(e){"use strict";function n(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var t=function(){function e(e,n){for(var t=0;t<n.length;t++){var i=n[t];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(n,t,i){return t&&e(n.prototype,t),i&&e(n,i),n}}(),i=function(){function e(t,i){return n(this,e),this.data=t,this.parent=i,this}return t(e,[{key:"addChild",value:function(n){var t=new e(n,this);return this.children||(this.children=[]),this.children.push(t),t}},{key:"find",value:function(e){if(e===this.data)return this;if(this.children)for(var n=0,t=this.children.length,i=null;t>n;n++)if(i=this.children[n].find(e))return i;return null}},{key:"leaves",value:function i(){if(!this.children||0===this.children.length)return[this];var i=[];if(this.children)for(var e=0,n=this.children.length;n>e;e++)i.push.apply(i,this.children[e].leaves());return i}},{key:"root",value:function(){return this.parent?this.parent.root():this}},{key:"forEach",value:function(e){if("function"!=typeof e)throw new TypeError("forEach() callback must be a function");if(e(this),this.children)for(var n=0,t=this.children.length;t>n;n++)e(this.children[n]);return this}},{key:"numChildren",value:function(){return this.children?this.children.length:0}}]),e}();e.TreeNode=i}); | ||
!function(e,n){if("function"==typeof define&&define.amd)define(["exports"],n);else if("undefined"!=typeof exports)n(exports);else{var t={exports:{}};n(t.exports),e.treenode=t.exports}}(this,function(e){"use strict";function n(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var t=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}(),r=function(){function e(t,r){return n(this,e),this.data=t,this.parent=r,this}return t(e,[{key:"addChild",value:function(n){var t=new e(n,this);return this.children||(this.children=[]),this.children.push(t),t}},{key:"find",value:function(e){if(e===this.data)return this;if(this.children)for(var n=0,t=this.children.length,r=null;t>n;n++)if(r=this.children[n].find(e))return r;return null}},{key:"leaves",value:function r(){if(!this.children||0===this.children.length)return[this];var r=[];if(this.children)for(var e=0,n=this.children.length;n>e;e++)r.push.apply(r,this.children[e].leaves());return r}},{key:"root",value:function(){return this.parent?this.parent.root():this}},{key:"forEach",value:function(e){if("function"!=typeof e)throw new TypeError("forEach() callback must be a function");if(e(this),this.children)for(var n=0,t=this.children.length;t>n;n++)this.children[n].forEach(e);return this}},{key:"numChildren",value:function(){return this.children?this.children.length:0}}]),e}();e.TreeNode=r}); |
{ | ||
"name": "treenode", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Very simple tree data structure in JS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -40,3 +40,3 @@ Tree Node | ||
var node = tree.addChild(someObject); | ||
var match = tree.findNode(someObject); // match === node | ||
var match = tree.find(someObject); // match === node | ||
@@ -63,2 +63,3 @@ // Find the tree root, from any node | ||
* 0.2.3 Make forEach() properly recursive | ||
* 0.2.2 Don't assume existence of children array. Added numChildren() helper | ||
@@ -65,0 +66,0 @@ * 0.2.1 Remove sourcemaps from non-minified prod file |
@@ -105,3 +105,3 @@ /** | ||
for (let i = 0, length = this.children.length; i < length; i++) { | ||
callback(this.children[i]); | ||
this.children[i].forEach(callback); | ||
} | ||
@@ -108,0 +108,0 @@ } |
@@ -62,2 +62,3 @@ var TreeNode = require('../dist/treenode').TreeNode; | ||
var childNode = intermediateNode.addChild(data[2]); | ||
var grandchildNode = childNode.addChild(data[3]); | ||
@@ -71,2 +72,3 @@ intermediateNode.forEach(function(node) { | ||
expect(childNode.data.status).toBe('updated'); | ||
expect(grandchildNode.data.status).toBe('updated'); | ||
}); | ||
@@ -73,0 +75,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67343
418
71