mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-29 11:00:12 +00:00
cleaned up the format a bit...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
e4997c1d52
commit
3a48b532f6
48
diff.js
48
diff.js
@ -246,6 +246,7 @@ var getDiffSections = function(A, B, cmp, min_chunk){
|
|||||||
// // holds both index and attribute keys (mode-dependant)...
|
// // holds both index and attribute keys (mode-dependant)...
|
||||||
// items: [
|
// items: [
|
||||||
// // Simple item diff...
|
// // Simple item diff...
|
||||||
|
// // XXX unused....
|
||||||
// [<key>, <diff>],
|
// [<key>, <diff>],
|
||||||
//
|
//
|
||||||
// // [S]plice section starting at key...
|
// // [S]plice section starting at key...
|
||||||
@ -263,6 +264,9 @@ var getDiffSections = function(A, B, cmp, min_chunk){
|
|||||||
//
|
//
|
||||||
// items: [
|
// items: [
|
||||||
// [<key>, <diff>],
|
// [<key>, <diff>],
|
||||||
|
//
|
||||||
|
// // XXX unused....
|
||||||
|
// [<key-a>, <key-b>, <diff>],
|
||||||
// ...
|
// ...
|
||||||
// ],
|
// ],
|
||||||
// item_order: <array-diff>,
|
// item_order: <array-diff>,
|
||||||
@ -318,30 +322,31 @@ function(A, B, options, cache){
|
|||||||
length: [A.length, B.length],
|
length: [A.length, B.length],
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX diff the gaps...
|
// diff the gaps...
|
||||||
res.items = getDiffSections(A, B, cmp)
|
res.items = getDiffSections(A, B, cmp)
|
||||||
.map(function(gap){
|
.map(function(gap){
|
||||||
|
var i = gap[0][0]
|
||||||
|
var j = gap[1][0]
|
||||||
var a = gap[0][1]
|
var a = gap[0][1]
|
||||||
var b = gap[1][1]
|
var b = gap[1][1]
|
||||||
|
|
||||||
var i = gap[0][0]
|
|
||||||
var j = gap[1][0]
|
|
||||||
|
|
||||||
return a
|
return a
|
||||||
.map(function(e, n){
|
.map(function(e, n){
|
||||||
return {
|
return [
|
||||||
A: i+n,
|
i+n,
|
||||||
B: j+n,
|
j+n,
|
||||||
diff: cacheDiff(e, b.length > n ? b[n] : NONE)
|
cacheDiff(e, b.length > n ? b[n] : NONE)
|
||||||
} })
|
] })
|
||||||
.concat(b.slice(a.length)
|
.concat(b.slice(a.length)
|
||||||
.map(function(e, n){
|
.map(function(e, n){
|
||||||
return {
|
return [
|
||||||
A: a.length + i+n,
|
a.length + i+n,
|
||||||
B: a.length + j+n,
|
a.length + j+n,
|
||||||
diff: cacheDiff(a.length > n ? a[n] : NONE, e)
|
cacheDiff(a.length > n ? a[n] : NONE, e)
|
||||||
} }))
|
] }))
|
||||||
})
|
})
|
||||||
|
.reduce(function(res, e){
|
||||||
|
return res.concat(e) }, [])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -373,6 +378,7 @@ function(A, B, options, cache){
|
|||||||
|
|
||||||
_diff_items(cacheDiff, res, A, B, options)
|
_diff_items(cacheDiff, res, A, B, options)
|
||||||
|
|
||||||
|
/* XXX
|
||||||
// XXX this should be applicable to JSON too...
|
// XXX this should be applicable to JSON too...
|
||||||
options.mode != 'JSON'
|
options.mode != 'JSON'
|
||||||
&& _diff_item_order(cacheDiff, res, A, B, options)
|
&& _diff_item_order(cacheDiff, res, A, B, options)
|
||||||
@ -386,8 +392,10 @@ function(A, B, options, cache){
|
|||||||
|
|
||||||
// XXX .__proto___ (???)
|
// XXX .__proto___ (???)
|
||||||
}
|
}
|
||||||
|
//*/
|
||||||
|
|
||||||
return ((res.item_order || []).length + (res.items || []).length) == 0 ?
|
return ((res.item_order || []).length
|
||||||
|
+ (res.items || []).length) == 0 ?
|
||||||
null
|
null
|
||||||
: res
|
: res
|
||||||
}
|
}
|
||||||
@ -414,9 +422,10 @@ function(diff, res, path){
|
|||||||
|
|
||||||
// Array...
|
// Array...
|
||||||
} else if(diff.type == 'Array'){
|
} else if(diff.type == 'Array'){
|
||||||
diff.items.forEach(function(e){
|
diff.items
|
||||||
var i = e[0]
|
.forEach(function(e){
|
||||||
var v = e[1]
|
var i = [e[0], e[1]]
|
||||||
|
var v = e[2]
|
||||||
var p = path.concat([i])
|
var p = path.concat([i])
|
||||||
|
|
||||||
flatten(v, res, p)
|
flatten(v, res, p)
|
||||||
@ -424,7 +433,8 @@ function(diff, res, path){
|
|||||||
|
|
||||||
// Object...
|
// Object...
|
||||||
} else if(diff.type == 'Object'){
|
} else if(diff.type == 'Object'){
|
||||||
diff.items.forEach(function(e){
|
diff.items
|
||||||
|
.forEach(function(e){
|
||||||
var i = e[0]
|
var i = e[0]
|
||||||
var v = e[1]
|
var v = e[1]
|
||||||
var p = path.concat([i])
|
var p = path.concat([i])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user