tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2021-05-28 19:37:48 +03:00
parent 987c4c2c79
commit 255ff641fd

View File

@ -113,20 +113,21 @@ function*(obj){
} }
// XXX use STOP...
var getHandlers = var getHandlers =
module.getHandlers = module.getHandlers =
function(obj, handlers=module.HANDLERS){ function(obj, handlers=module.HANDLERS){
var stop = false return [...Object.entries(handlers)
return Object.entries(handlers) .iter()
.filter(function([k, v]){ .filter(function([k, v]){
return stop ? if(v.final
false && v.match
// XXX this is a bit ugly... && v.match(obj)){
: (v.match throw types.STOP(true) }
&& v.match(obj) return v.match
&& (stop = v.final, true)) }) && v.match(obj) })
.map(function([k, v]){ .map(function([k, v]){
return v }) } return v })] }
@ -186,17 +187,17 @@ function*(obj, path=[], options={}){
: subtree(handler.handle(obj, path, options)) }) } : subtree(handler.handle(obj, path, options)) }) }
var _serializePath = function(p){
// XXX need a better way to serialize the path...
var serializePathElem = function(p){
return typeof(p) == 'object' ? return typeof(p) == 'object' ?
JSON.stringify(p) JSON.stringify(p)
: p } : p }
var serializePath = function(p){ var serializePath = function(p){
return '/'+ p.map(_serializePath).join('/') } return '/'+ p.map(serializePathElem).join('/') }
var serializePaths =
// XXX need a better way to serialize the path... module.serializePaths =
var shandle = types.generator.iter
module.shandle =
handle
.map(function([p, v]){ .map(function([p, v]){
return ( return (
// XXX revise... // XXX revise...
@ -234,7 +235,11 @@ var o = {
// loop... // loop...
o.object.y = o.object o.object.y = o.object
console.log([...shandle(o)])
console.log([
...handle(o)
.chain(serializePaths)])