mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-29 02:50:10 +00:00
some fixes and cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
4afcdfb26e
commit
37e542c6c5
25
diff.js
25
diff.js
@ -530,7 +530,6 @@ var Types = {
|
|||||||
|
|
||||||
// Diff format walker...
|
// Diff format walker...
|
||||||
//
|
//
|
||||||
// XXX need to sort out return values...
|
|
||||||
walk: function(diff, func, path){
|
walk: function(diff, func, path){
|
||||||
// no changes...
|
// no changes...
|
||||||
if(diff == null){
|
if(diff == null){
|
||||||
@ -564,7 +563,6 @@ var Types = {
|
|||||||
// the changes in ordered containers...
|
// the changes in ordered containers...
|
||||||
// ...it might also be possible to provide vertical/topological
|
// ...it might also be possible to provide vertical/topological
|
||||||
// "fuzz", need to think about this...
|
// "fuzz", need to think about this...
|
||||||
// XXX TEST: the format should survive JSON.parse(JSON.stringify(..))...
|
|
||||||
flatten: function(diff, options){
|
flatten: function(diff, options){
|
||||||
options = options || {}
|
options = options || {}
|
||||||
var res = []
|
var res = []
|
||||||
@ -573,10 +571,11 @@ var Types = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// Reverse diff...
|
||||||
|
//
|
||||||
reverse: function(diff){
|
reverse: function(diff){
|
||||||
var that = this
|
var that = this
|
||||||
var res = []
|
return this.walk(diff, function(change){
|
||||||
this.walk(diff, function(change){
|
|
||||||
var c = Object.assign({}, change)
|
var c = Object.assign({}, change)
|
||||||
|
|
||||||
// path...
|
// path...
|
||||||
@ -589,9 +588,8 @@ var Types = {
|
|||||||
type.reverse
|
type.reverse
|
||||||
&& (c = type.reverse.call(that, c)) })
|
&& (c = type.reverse.call(that, c)) })
|
||||||
|
|
||||||
res.push(c)
|
return c
|
||||||
})
|
})
|
||||||
return res
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -861,12 +859,17 @@ Types.set('Basic', {
|
|||||||
return func(change)
|
return func(change)
|
||||||
},
|
},
|
||||||
reverse: function(change){
|
reverse: function(change){
|
||||||
var t = change.B
|
|
||||||
var b = 'B' in change
|
var b = 'B' in change
|
||||||
'A' in change
|
var a = 'A' in change
|
||||||
&& (change.B = change.A)
|
var t = change.B
|
||||||
b
|
|
||||||
&& (change.A = t)
|
a ?
|
||||||
|
(change.B = change.A)
|
||||||
|
: (delete change.B)
|
||||||
|
b ?
|
||||||
|
(change.A = t)
|
||||||
|
: (delete change.A)
|
||||||
|
|
||||||
return change
|
return change
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user