added tests/docs...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-05-11 14:54:48 +03:00
parent dcfd4d33c5
commit 087c4a4ccc

View File

@ -695,8 +695,7 @@ var BaseBrowserPrototype = {
recursion, recursion,
...(formArgs instanceof Function ? ...(formArgs instanceof Function ?
[formArgs] [formArgs]
: []), : [walkable]),
walkable,
options, context) } options, context) }
return (list === false ? return (list === false ?
@ -794,12 +793,23 @@ var BaseBrowserPrototype = {
: this.items)) }, : this.items)) },
// Text render... // Test/Example Text renders...
// //
// This is mainly here for doc/debug purposes... // Recursively render the browser as text tree...
// ._test_texttree(..)
// -> string
// //
// XXX rename this?? // Recursively render the browser as text tree with manual nesting...
text: function(options, context){ // ._test_texttree_manual(..)
// -> string
//
// Build a nested object tree from the browser...
// ._test_tree(..)
// -> object
//
_test_texttree: function(options, context){
// NOTE: here we do not care about the topology (other than path
// depth) and just handle items...
return this return this
.walk( .walk(
function(node, i, path){ function(node, i, path){
@ -808,29 +818,66 @@ var BaseBrowserPrototype = {
.map(e => ' ') .map(e => ' ')
.join('') + (node.value || node) .join('') + (node.value || node)
: [] }, : [] },
'text', '_test_texttree',
function(func, i, path, options, context){ function(func, i, path, options, context){
return [options, context] }, return [options, context] },
options, context) options, context)
.join('\n') }, .join('\n') },
// XXX test manual recursion... _test_texttree_manual: function(options, context){
text2: function(options, context){ // NOTE: here we do basic topology -- append children to their
// respective node...
return this return this
.walk( .walk(
function(node, i, path, next){ function(node, i, path, next){
return node == null ? return node == null ?
[] []
// make a node...
: [path.slice(1) : [path.slice(1)
.map(e => ' ') .map(e => ' ')
.join('') + (node.value || node)] .join('') + (node.value || node)]
// append child nodes if present...
.concat(node.children ? .concat(node.children ?
next() next()
: []) }, : []) },
'text2', '_test_texttree_manual',
function(func, i, path, options, context){ function(func, i, path, options, context){
return [options, context] }, return [options, context] },
options, context) options, context)
.join('\n') }, .join('\n') },
_test_tree: function(options, context){
var toObject = function(res, e){
if(e == null || e[0] == null){
return res
}
res[e[0]] = e[1] instanceof Array ?
// handle nested arrays...
// NOTE: these did not get through the .reduce(..) below
// as they are simple arrays that do not implement
// either .walk(..) or ._test_tree(..)
e.slice(1).reduce(toObject, {})
: e[1]
return res
}
return this
// build [key, children] pairs...
.walk(
function(node, i, path, next){
return node == null ?
[]
// make a node...
: [[(node.value || node)]
// append child nodes if present...
.concat(node.children ?
next()
: null) ] },
'_test_tree',
function(func, i, path, options, context){
return [options, context] },
options, context)
// construct the object...
.reduce(toObject, {}) },
paths: function(options, context){ paths: function(options, context){
return this.walk( return this.walk(
function(n, i, p){ function(n, i, p){
@ -846,6 +893,7 @@ var BaseBrowserPrototype = {
return [options, context] }, return [options, context] },
options, context) }, options, context) },
// Extended map... // Extended map...
// //
// Get all items... // Get all items...