tweaking + docs...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-08-25 02:30:23 +03:00
parent c045d67a89
commit 20e6aed9c2

View File

@ -1931,38 +1931,49 @@ var BaseBrowserPrototype = {
// XXX EXPERIMENTAL -- an attempt to simplify walking... // XXX EXPERIMENTAL -- an attempt to simplify walking...
// Walk the browser...
// //
// .walk(func[, options]) // Get list of nodes...
// .walk()
// .walk(null[, options])
// -> list
//
// Walk the tree passing each elem to func(..)
// .walk(func(..)[, options])
// -> list // -> list
// -> res // -> res
// //
// //
// func(elem, i, path, next(..), stop(..)) // Handle elem...
// -> [item, ..] // func(elem, index, path, next(..), stop(..))
// -> item // -> [item, ..]
// -> item
// //
// //
// Ignore current .children... // Ignore current .children...
// next() // next()
// //
// Explicitly pass the children to handle... // Explicitly pass children to be handled...
// next(browser) // next(browser)
// next([elem, ...]) // next([elem, ...])
// //
// //
// Stop walking (returning undefined)... // Stop walking (return undefined)...
// stop() // stop()
// //
// Stop walking and return res... // Stop walking and return res...
// stop(res) // stop(res)
// //
// //
// If func(..) returns an array it's content is merged (.flat()) into // NOTE: stop(..) breaks execution so nothing after it is called
// .walk(..)'s return value, this enables it to: // in the function will get reached.
// - return more than one value per item by returning an array of values // NOTE: if func(..) returns an array it's content is merged (.flat())
// - return no values for an item by returning [] // into .walk(..)'s return value, this enables it to:
// // - return more than one value per item by returning an
// NOTE: to explicitly return an array wrap it in another array. // array of values
// - return no values for an item by returning []
// NOTE: to explicitly return an array from func(..) wrap it in
// another array.
// //
// //
// //
@ -2026,7 +2037,7 @@ var BaseBrowserPrototype = {
// children and return the result to the caller??? // children and return the result to the caller???
walk2: function(func, options){ walk2: function(func, options){
var that = this var that = this
var [func, options={}, path=[], context={}] = [...arguments] var [func=null, options={}, path=[], context={}] = [...arguments]
// context... // context...
context.root = context.root || this context.root = context.root || this
@ -2092,7 +2103,7 @@ var BaseBrowserPrototype = {
return (item = return (item =
item !== undefined ? item !== undefined ?
item item
: !skipItem ? : !skipItem && func ?
[ func.call(that, elem, context.index++, p, next, stop) ].flat() [ func.call(that, elem, context.index++, p, next, stop) ].flat()
: []) } : []) }
// pre-call the item if reverse is not 'full'... // pre-call the item if reverse is not 'full'...
@ -2155,10 +2166,18 @@ var BaseBrowserPrototype = {
// basic iteration... // basic iteration...
map2: function(func, options){ map2: function(func, options){
var that = this var that = this
options = !(options || {}).defaultReverse ? var args = [...arguments]
func = (args[0] instanceof Function
|| args[0] == null) ?
args.shift()
: undefined
// NOTE: we do not inherit options from this.options here is it
// will be done in .walk(..)
options = args.shift() || {}
options = !options.defaultReverse ?
Object.assign({}, Object.assign({},
options || {}, options,
{ defaultReverse: 'full' }) { defaultReverse: 'flat' })
: options : options
return this.walk2( return this.walk2(
function(e, i, p){ function(e, i, p){
@ -2201,7 +2220,9 @@ var BaseBrowserPrototype = {
options || {}, options || {},
{rawResults: true})) }, {rawResults: true})) },
// XXX search(..), get(..), ... // XXX
search2: function(){},
get2: function(){},