mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-29 02:50:10 +00:00
refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
f6018a04f1
commit
74cd12cd47
108
diff2.js
108
diff2.js
@ -104,8 +104,36 @@ module.CONTENT =
|
|||||||
var Walk =
|
var Walk =
|
||||||
module.Walk =
|
module.Walk =
|
||||||
object.Constructor('Walk', {
|
object.Constructor('Walk', {
|
||||||
|
|
||||||
|
//
|
||||||
|
// .handler(obj, path, next, type)
|
||||||
|
// -> <generator>
|
||||||
|
// -> [path, ...]
|
||||||
|
//
|
||||||
|
// XXX should there be a default here???
|
||||||
handler: undefined,
|
handler: undefined,
|
||||||
|
|
||||||
|
//
|
||||||
|
// Format:
|
||||||
|
// {
|
||||||
|
// <type>: <func>,
|
||||||
|
//
|
||||||
|
// <type>: {
|
||||||
|
// list: <func>,
|
||||||
|
// ...
|
||||||
|
// },
|
||||||
|
//
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// XXX should there be a default here???
|
||||||
listers: undefined,
|
listers: undefined,
|
||||||
|
|
||||||
|
//
|
||||||
|
// .normalizePath(<path>)
|
||||||
|
// -> <path>
|
||||||
|
//
|
||||||
|
// (optional)
|
||||||
normalizePath: undefined,
|
normalizePath: undefined,
|
||||||
|
|
||||||
// NOTE: handler argument always overwrites the value given in options...
|
// NOTE: handler argument always overwrites the value given in options...
|
||||||
@ -184,21 +212,37 @@ object.Constructor('Walk', {
|
|||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
//
|
// XXX we can treat the output as a stack language...
|
||||||
// Format:
|
// ...need to clear out unneeded stuff...
|
||||||
// {
|
// XXX add function support...
|
||||||
// <type>: <func>,
|
// XXX this needs .name set correctly...
|
||||||
//
|
var objectWalker =
|
||||||
// <type>: {
|
module.objectWalker =
|
||||||
// list: <func>,
|
Walk({
|
||||||
// ...
|
// support string paths...
|
||||||
// },
|
normalizePath: function(path){
|
||||||
//
|
return path instanceof Array ?
|
||||||
// ...
|
path
|
||||||
// }
|
: typeof(path) == 'string' ?
|
||||||
//
|
str2path(path)
|
||||||
var OBJECT_LISTERS =
|
: [] },
|
||||||
module.OBJECT_LISTERS = {
|
|
||||||
|
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...
|
// prevent dissecting null...
|
||||||
null: function(obj){
|
null: function(obj){
|
||||||
if(obj === null){
|
if(obj === null){
|
||||||
@ -243,39 +287,13 @@ module.OBJECT_LISTERS = {
|
|||||||
return typeof(obj) == 'object'
|
return typeof(obj) == 'object'
|
||||||
&& obj.constructor.prototype !== obj.__proto__
|
&& obj.constructor.prototype !== obj.__proto__
|
||||||
&& [['__proto__', 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...
|
// like objectWalker(..) but with 'text' support...
|
||||||
//
|
//
|
||||||
var objectWalkerWithText =
|
var objectWalkerWithText =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user