mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-29 02:50:10 +00:00
tweaking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
14c7ddae45
commit
987c4c2c79
21
diff2.js
21
diff2.js
@ -87,6 +87,7 @@ module.HANDLERS = {
|
|||||||
handle: function(obj){
|
handle: function(obj){
|
||||||
// XXX for some reason the .entries() iterator does not have
|
// XXX for some reason the .entries() iterator does not have
|
||||||
// the generaator methods -- we can't call obj.entries().map(..)...
|
// the generaator methods -- we can't call obj.entries().map(..)...
|
||||||
|
// XXX for sets k is the same a v... not sure how to handle this...
|
||||||
return [ [...obj.entries()]
|
return [ [...obj.entries()]
|
||||||
.map(function([k, v]){
|
.map(function([k, v]){
|
||||||
return [[k], v] }), ] },
|
return [[k], v] }), ] },
|
||||||
@ -140,7 +141,7 @@ function*(obj, path=[], options={}){
|
|||||||
options.seen || new Map()
|
options.seen || new Map()
|
||||||
if(seen.has(obj)){
|
if(seen.has(obj)){
|
||||||
// XXX revise format...
|
// XXX revise format...
|
||||||
yield ['LINK', seen.get(obj)]
|
yield [path, ['LINK', seen.get(obj)]]
|
||||||
return }
|
return }
|
||||||
typeof(obj) == 'object'
|
typeof(obj) == 'object'
|
||||||
&& seen.set(obj, path)
|
&& seen.set(obj, path)
|
||||||
@ -185,6 +186,13 @@ function*(obj, path=[], options={}){
|
|||||||
: subtree(handler.handle(obj, path, options)) }) }
|
: subtree(handler.handle(obj, path, options)) }) }
|
||||||
|
|
||||||
|
|
||||||
|
var _serializePath = function(p){
|
||||||
|
return typeof(p) == 'object' ?
|
||||||
|
JSON.stringify(p)
|
||||||
|
: p }
|
||||||
|
var serializePath = function(p){
|
||||||
|
return '/'+ p.map(_serializePath).join('/') }
|
||||||
|
|
||||||
// XXX need a better way to serialize the path...
|
// XXX need a better way to serialize the path...
|
||||||
var shandle =
|
var shandle =
|
||||||
module.shandle =
|
module.shandle =
|
||||||
@ -192,9 +200,10 @@ handle
|
|||||||
.map(function([p, v]){
|
.map(function([p, v]){
|
||||||
return (
|
return (
|
||||||
// XXX revise...
|
// XXX revise...
|
||||||
p == 'LINK' ?
|
v instanceof Array && v[0] == 'LINK' ?
|
||||||
['LINK', '/'+ v.join('/')]
|
[serializePath(p),
|
||||||
: ['/'+ p.join('/'), v] ) })
|
'LINK', serializePath(v[1])]
|
||||||
|
: [serializePath(p), v] ) })
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -214,7 +223,7 @@ var o = {
|
|||||||
empty_array: [],
|
empty_array: [],
|
||||||
array: [1, 2, 3],
|
array: [1, 2, 3],
|
||||||
|
|
||||||
// XXX set keys are a bit odd -- the key is the object itself...
|
// XXX set key is the object itself, is this what we want???
|
||||||
set: new Set([1, [], {a:1}]),
|
set: new Set([1, [], {a:1}]),
|
||||||
map: new Map([[[], 123], [321, {}]]),
|
map: new Map([[[], 123], [321, {}]]),
|
||||||
|
|
||||||
@ -229,5 +238,7 @@ 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