refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2021-06-30 10:53:38 +03:00
parent f6018a04f1
commit 74cd12cd47

108
diff2.js
View File

@ -104,8 +104,36 @@ module.CONTENT =
var Walk =
module.Walk =
object.Constructor('Walk', {
//
// .handler(obj, path, next, type)
// -> <generator>
// -> [path, ...]
//
// XXX should there be a default here???
handler: undefined,
//
// Format:
// {
// <type>: <func>,
//
// <type>: {
// list: <func>,
// ...
// },
//
// ...
// }
//
// XXX should there be a default here???
listers: undefined,
//
// .normalizePath(<path>)
// -> <path>
//
// (optional)
normalizePath: undefined,
// NOTE: handler argument always overwrites the value given in options...
@ -184,21 +212,37 @@ object.Constructor('Walk', {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// Format:
// {
// <type>: <func>,
//
// <type>: {
// list: <func>,
// ...
// },
//
// ...
// }
//
var OBJECT_LISTERS =
module.OBJECT_LISTERS = {
// XXX we can treat the output as a stack language...
// ...need to clear out unneeded stuff...
// XXX add function support...
// XXX this needs .name set correctly...
var objectWalker =
module.objectWalker =
Walk({
// support string paths...
normalizePath: function(path){
return path instanceof Array ?
path
: typeof(path) == 'string' ?
str2path(path)
: [] },
handler: function(obj, path, next, type){
return type == 'LINK' ?
[path, 'LINK', next]
: [
path,
// null...
obj == null ?
obj
// objects...
: typeof(obj) == 'object' ?
{type: obj.constructor.name}
// primitives...
: obj,
] },
listers: {
// prevent dissecting null...
null: function(obj){
if(obj === null){
@ -243,39 +287,13 @@ module.OBJECT_LISTERS = {
return typeof(obj) == 'object'
&& obj.constructor.prototype !== obj.__proto__
&& [['__proto__', obj.__proto__]] },
}
// XXX add function support...
// XXX this needs .name set correctly...
var objectWalker =
module.objectWalker =
Walk({
handler: function(obj, path, next, type){
return type == 'LINK' ?
[path, 'LINK', next]
: [
path,
// null...
obj == null ?
obj
// objects...
: typeof(obj) == 'object' ?
{type: obj.constructor.name}
// primitives...
: obj,
] },
listers: module.OBJECT_LISTERS,
// support string paths...
normalizePath: function(path){
return path instanceof Array ?
path
: typeof(path) == 'string' ?
str2path(path)
: [] },
},
})
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// like objectWalker(..) but with 'text' support...
//
var objectWalkerWithText =