mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-29 11:00:12 +00:00
added a ad-hoc test...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
1369934117
commit
14c7ddae45
65
diff2.js
65
diff2.js
@ -16,6 +16,7 @@ var types = require('ig-types')
|
|||||||
var HANDLERS =
|
var HANDLERS =
|
||||||
module.HANDLERS = {
|
module.HANDLERS = {
|
||||||
/*/ XXX
|
/*/ XXX
|
||||||
|
// XXX need option threading...
|
||||||
// XXX need to be able to stop processing handlers...
|
// XXX need to be able to stop processing handlers...
|
||||||
// for example when handling 'text' we do not need to also call
|
// for example when handling 'text' we do not need to also call
|
||||||
// 'value' too...
|
// 'value' too...
|
||||||
@ -32,6 +33,14 @@ module.HANDLERS = {
|
|||||||
},
|
},
|
||||||
//*/
|
//*/
|
||||||
|
|
||||||
|
null: {
|
||||||
|
final: true,
|
||||||
|
match: function(obj){
|
||||||
|
return obj === null },
|
||||||
|
handle: function(obj){
|
||||||
|
return [[], obj] },
|
||||||
|
},
|
||||||
|
|
||||||
value: {
|
value: {
|
||||||
match: function(obj){
|
match: function(obj){
|
||||||
return typeof(obj) != 'object' },
|
return typeof(obj) != 'object' },
|
||||||
@ -50,6 +59,16 @@ module.HANDLERS = {
|
|||||||
}] },
|
}] },
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// XXX need to optionally treat special attributes...
|
||||||
|
// .__proto__
|
||||||
|
specialKeys: {
|
||||||
|
//match: function(obj){
|
||||||
|
// return typeof(obj) == 'object' },
|
||||||
|
handle: function(obj){
|
||||||
|
// XXX
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
// XXX do we need to also traverse/index the keys???
|
// XXX do we need to also traverse/index the keys???
|
||||||
// ...if yes then we'll need to somehow indicate a path to a key...
|
// ...if yes then we'll need to somehow indicate a path to a key...
|
||||||
// one way to do this is to add virtual paths and link to them...
|
// one way to do this is to add virtual paths and link to them...
|
||||||
@ -73,15 +92,8 @@ module.HANDLERS = {
|
|||||||
return [[k], v] }), ] },
|
return [[k], v] }), ] },
|
||||||
},
|
},
|
||||||
|
|
||||||
// XXX need to optionally treat special attributes...
|
|
||||||
specialKeys: {
|
|
||||||
match: function(obj){
|
|
||||||
return false },
|
|
||||||
handle: function(obj){
|
|
||||||
// XXX
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// XXX do we need to treat array keys as a special case???
|
// XXX do we need to treat array keys as a special case???
|
||||||
|
// XXX need to optionally handle props...
|
||||||
keys: {
|
keys: {
|
||||||
match: function(obj){
|
match: function(obj){
|
||||||
return typeof(obj) == 'object' },
|
return typeof(obj) == 'object' },
|
||||||
@ -103,9 +115,15 @@ function*(obj){
|
|||||||
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)
|
||||||
.filter(function([k, v]){
|
.filter(function([k, v]){
|
||||||
return v.match(obj) })
|
return stop ?
|
||||||
|
false
|
||||||
|
// XXX this is a bit ugly...
|
||||||
|
: (v.match
|
||||||
|
&& v.match(obj)
|
||||||
|
&& (stop = v.final, true)) })
|
||||||
.map(function([k, v]){
|
.map(function([k, v]){
|
||||||
return v }) }
|
return v }) }
|
||||||
|
|
||||||
@ -181,6 +199,35 @@ handle
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------
|
||||||
|
// XXX move to test...
|
||||||
|
|
||||||
|
var o = {
|
||||||
|
number: 123,
|
||||||
|
string: 'abc',
|
||||||
|
|
||||||
|
// XXX add a mode to unify these...
|
||||||
|
'null': null,
|
||||||
|
'undefined': undefined,
|
||||||
|
|
||||||
|
|
||||||
|
empty_array: [],
|
||||||
|
array: [1, 2, 3],
|
||||||
|
|
||||||
|
// XXX set keys are a bit odd -- the key is the object itself...
|
||||||
|
set: new Set([1, [], {a:1}]),
|
||||||
|
map: new Map([[[], 123], [321, {}]]),
|
||||||
|
|
||||||
|
object: {
|
||||||
|
x: {},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// loop...
|
||||||
|
o.object.y = o.object
|
||||||
|
|
||||||
|
console.log([...shandle(o)])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* vim:set ts=4 sw=4 : */ return module })
|
* vim:set ts=4 sw=4 : */ return module })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user