-
Notifications
You must be signed in to change notification settings - Fork 9
Methods & Callbacks
Alex edited this page Jun 14, 2015
·
2 revisions
Returns the state described of iteration protocol.
Returns true
if any is node.
var iterator = new RecursiveIterator(root);
var item = iterator.next();
iterator.isNode(item.node);
You can override this function for custom behaviour:
var iterator = new RecursiveIterator(root);
iterator.isNode = function(any) {
return {Boolean};
};
By default node is {Object}
.
Returns true
if node is leaf. Leaf is all primitive types.
var iterator = new RecursiveIterator(root);
var item = iterator.next();
iterator.isLeaf(item.node);
Returns true
if object is circular reference.
var iterator = new RecursiveIterator(root);
var item = iterator.next();
iterator.isCircular(item.node);
Clears cache and queue. It calls automatically at the end of the loop.
Returns descriptor of state.
Returns array of states of child nodes.
It calls for each node. If returns false
node will be skipped:
var root = {
object: {
number: 1
},
string: 'foo'
};
var iterator = new RecursiveIterator(root);
iterator.onStepInto = function(state) {
// prevent step into node
return false;
};
for(let {node, path} of iterator) {
console.log(path.join('.'), node);
}
// object Object {number: 1}
// string foo