cleanup and refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-04-28 18:44:02 +03:00
parent ce221b4b34
commit e718df1bea

View File

@ -612,7 +612,9 @@ var BaseBrowserPrototype = {
: [] : []
path = path instanceof Array ? path : [path] path = path instanceof Array ? path : [path]
options = args.pop() || {} options = args.pop() || {}
// set call context... // set call context...
// XXX revise this....
options = !options.root ? options = !options.root ?
Object.assign({}, Object.assign({},
options, options,
@ -947,43 +949,28 @@ var BaseBrowserPrototype = {
&& path.length > 0 && path.length > 0
&& i == pattern } ) && i == pattern } )
/*
var Stop = new Error('Target found.')
var res
try {
//*/
return this.walk( return this.walk(
function(i, path, elem, doNested){ function(i, path, elem, doNested){
if(elem && func.call(this, elem, i, path)){ if(elem && func.call(this, elem, i, path)){
//res = elem
//throw Stop
return [elem] return [elem]
} }
return [] return []
}, },
/* XXX
function(_, i, path, sublist, options){ function(_, i, path, sublist, options){
// XXX does not work yet... // XXX does not work yet...
if(pattern instanceof Array //// skip paths that do not match...
&& pattern[path.length-1] != '*' //if(pattern instanceof Array
&& pattern[path.length-1] != path[path.length-1]){ // && pattern[path.length-1] != '*'
return [] // && pattern[path.length-1] != path[path.length-1]){
} // return []
//}
return sublist.search(pattern, i, path, options) return sublist.search(pattern, i, path, options)
}, },
...args, ...args,
options)
/* XXX need to do this only in the root call...
} catch(err){
if(err === Stop){
return res
}
throw err
}
//*/ //*/
options)
}, },
@ -1027,10 +1014,14 @@ var BaseBrowserPrototype = {
forEach: function(func, options){ forEach: function(func, options){
this.map(...arguments) this.map(...arguments)
return this }, return this },
// XXX should we use a recursive .walk(..), .map(..) .filter(..) or
// try and make do with what is available in a child???
filter: function(func, options){ filter: function(func, options){
return this.map(function(e, i, p, b){ return this.walk(function(i, p, e, b){
return func.call(this, e, i, p, b) ? [e] : [] }) return e && func.call(this, e, i, p, b) ? [e] : [] }) },
.flat() }, //return this.map(function(e, i, p, b){
// return func.call(this, e, i, p, b) ? [e] : [] })
//.flat() },
reduce: function(){}, reduce: function(){},
// Get item... // Get item...