docs, cleanup and minor tweaks...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-04-22 02:30:53 +03:00
parent e510ca7428
commit af1a315d6e

View File

@ -1308,7 +1308,11 @@ var BaseBrowserPrototype = {
// // If true skip iterating nested items... // // If true skip iterating nested items...
// skipNested: <bool>, // skipNested: <bool>,
// //
// // XXX
// reverseIteration: <bool>,
//
// // If true include inlined parent id in path... // // If true include inlined parent id in path...
// // XXX not implemented yet -- can we implement this???...
// inlinedPaths: <bool>, // inlinedPaths: <bool>,
// } // }
// //
@ -1340,6 +1344,7 @@ var BaseBrowserPrototype = {
var skipNested = !options.iterateAll && options.skipNested var skipNested = !options.iterateAll && options.skipNested
var reverse = !!options.reverseIteration var reverse = !!options.reverseIteration
// level walk function...
var walk = function(path, list){ var walk = function(path, list){
return list return list
// reverse the items... // reverse the items...
@ -1350,12 +1355,17 @@ var BaseBrowserPrototype = {
this.slice().reverse() this.slice().reverse()
: this }) : this })
.map(function(elem){ .map(function(elem){
var elem_id = elem.id || elem.value // skip non-iterable items...
if(!iterateNonIterable && elem.noniterable){
return []
}
var elem_id = elem.id || elem.value
// these will be set in the return expression below... // these will be set in the return expression below...
var sublist var sublist
var p var p
// nested browser/list handler...
var nested_called = false var nested_called = false
var nested = function(list, opts){ var nested = function(list, opts){
var skip = skipNested && !list var skip = skipNested && !list
@ -1370,51 +1380,42 @@ var BaseBrowserPrototype = {
[] []
:list instanceof Array ? :list instanceof Array ?
walk(p, list) walk(p, list)
// user-defined recursion (function)... // user-defined recursion...
: recursion instanceof Function ? : recursion instanceof Function ?
recursion.call(that, func, p, list, opts || options) recursion.call(that, func, p, list, opts || options)
: list[recursion || 'walk'](func, p, opts || options)) } : list[recursion || 'walk'](func, p, opts || options)) }
if(!iterateNonIterable && elem.noniterable){
return []
}
return ( return (
// inline browser or array... // inline browser or array...
(elem instanceof Array (elem instanceof Array
|| elem instanceof Browser) ? || elem instanceof Browser) ?
func.call(that, func.call(that,
p = path, p = path,
null, null, nested,
nested,
sublist = elem) sublist = elem)
// nested browser / array... // nested browser / array...
: (elem.sublist instanceof Browser : (elem.sublist instanceof Browser
|| elem.sublist instanceof Array) ? || elem.sublist instanceof Array) ?
func.call(that, func.call(that,
p = path.concat([elem_id]), p = path.concat([elem_id]),
elem, elem, nested,
nested,
sublist = elem.sublist) sublist = elem.sublist)
// normal element... // normal element...
: func.call(that, : func.call(that,
p = path.concat([elem_id]), p = path.concat([elem_id]),
elem, elem, null,
null,
sublist = null) ) sublist = null) )
// append nested elements... // append nested elements...
.concat((!sublist || nested_called) ? .concat((!sublist || nested_called) ?
[] []
: nested(sublist)) : nested(sublist))
}) })
.flat() .flat() }
}
return walk(path, this.items) return walk(path, this.items)
}, },
// XXX text2: function(options, renderer){
render2text: function(options, renderer){
var that = this var that = this
// XXX Q: should options and context be distinguished only via // XXX Q: should options and context be distinguished only via
// the .options attr as is the case now??? // the .options attr as is the case now???
@ -1453,13 +1454,14 @@ var BaseBrowserPrototype = {
: [item.value || item] : [item.value || item]
) }, ) },
function(func, path, sublist, options){ function(func, path, sublist, options){
return sublist.render2text(context) }, return sublist.text2(context) },
options) options)
return context.root === this ? return context.root === this ?
items.join('\n') items.join('\n')
: items : items
}, },
// XXX
render2: function(options, renderer){ render2: function(options, renderer){
var that = this var that = this
// XXX Q: should options and context be distinguished only via // XXX Q: should options and context be distinguished only via
@ -1506,7 +1508,10 @@ var BaseBrowserPrototype = {
: items : items
}, },
// XXX this is different to .map(..) in that here options.reverseIteration
// will reverse each level but keep the up-down order while
// .map({reverseIteration: true}) is similar to .map().reverse()
// ...not sure which is better or if we should support both...
map2: function(func, options){ map2: function(func, options){
var that = this var that = this