Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2021-07-01 16:39:12 +03:00
parent 74cd12cd47
commit 30573a7939

View File

@ -101,6 +101,7 @@ module.CONTENT =
// //
// XXX need to think about extension use-cases... // XXX need to think about extension use-cases...
// XXX should we move this to a separate lib??? // XXX should we move this to a separate lib???
// XXX add a way to do relative/full paths...
var Walk = var Walk =
module.Walk = module.Walk =
object.Constructor('Walk', { object.Constructor('Walk', {
@ -153,6 +154,7 @@ object.Constructor('Walk', {
: Object.assign( : Object.assign(
function*(){ yield handler.call(this, ...arguments) }, function*(){ yield handler.call(this, ...arguments) },
{toString: function(){ return handler.toString() }}) }, {toString: function(){ return handler.toString() }}) },
// XXX add options...
__call__: function*(_, obj, path=[], type='root', seen=new Map()){ __call__: function*(_, obj, path=[], type='root', seen=new Map()){
var that = this var that = this
path = this.normalizePath ? path = this.normalizePath ?
@ -197,6 +199,8 @@ object.Constructor('Walk', {
yield* items yield* items
.iter() .iter()
.map(function*([key, value]){ .map(function*([key, value]){
// XXX add relative path support...
// ...maybe [path, key] instead of path.concat(key) ???
yield* that(value, path.concat(key), type, seen) }) }) yield* that(value, path.concat(key), type, seen) }) })
// handle STOP... // handle STOP...
} catch(err){ } catch(err){