mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-28 18:40:09 +00:00
more experimenting...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
01c07bfe18
commit
112ca65a1d
53
diff2.js
53
diff2.js
@ -760,6 +760,7 @@ function(A, B, cmp){
|
|||||||
// [
|
// [
|
||||||
// // change...
|
// // change...
|
||||||
// [
|
// [
|
||||||
|
// // XXX do we need the indexes???
|
||||||
// <a-index>, <a-chunk>,
|
// <a-index>, <a-chunk>,
|
||||||
// <b-index>, <b-chunk>,
|
// <b-index>, <b-chunk>,
|
||||||
// ],
|
// ],
|
||||||
@ -779,7 +780,9 @@ function(A, B, cmp){
|
|||||||
var pa = 0
|
var pa = 0
|
||||||
var pb = 0
|
var pb = 0
|
||||||
return commonSections(A, B, cmp)
|
return commonSections(A, B, cmp)
|
||||||
|
// remove length...
|
||||||
.slice(1)
|
.slice(1)
|
||||||
|
// add rear block...
|
||||||
.concat([[A.length, B.length, 0]])
|
.concat([[A.length, B.length, 0]])
|
||||||
.reduce(function(gaps, [a, b, l]){
|
.reduce(function(gaps, [a, b, l]){
|
||||||
// only push changes of >0 length...
|
// only push changes of >0 length...
|
||||||
@ -797,6 +800,7 @@ function(A, B, cmp){
|
|||||||
return gaps }, []) }
|
return gaps }, []) }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// XXX if two sub-trees are different, do we treat them as a big set of
|
// XXX if two sub-trees are different, do we treat them as a big set of
|
||||||
// atomic changes or replace X with Y???
|
// atomic changes or replace X with Y???
|
||||||
@ -838,7 +842,7 @@ function(A, B, options={}){
|
|||||||
// XXX this completely ignores the path/key...
|
// XXX this completely ignores the path/key...
|
||||||
// XXX this works great for arrays but is questionable on other stuff...
|
// XXX this works great for arrays but is questionable on other stuff...
|
||||||
var valueDiff =
|
var valueDiff =
|
||||||
function(A, B){
|
function(A, B, options={}){
|
||||||
return diffSections(
|
return diffSections(
|
||||||
[...objectWalkerWithText(A)
|
[...objectWalkerWithText(A)
|
||||||
.chain(serializePaths)],
|
.chain(serializePaths)],
|
||||||
@ -856,6 +860,31 @@ function(A, B){
|
|||||||
var diff = keyValueDiff
|
var diff = keyValueDiff
|
||||||
|
|
||||||
|
|
||||||
|
// convert diff sections into diff...
|
||||||
|
//
|
||||||
|
// XXX add context lines...
|
||||||
|
var toDiff =
|
||||||
|
module.toDiff =
|
||||||
|
function*(A, B, options={}){
|
||||||
|
yield* diff(A, B, options)
|
||||||
|
.iter()
|
||||||
|
.map(function*([ia, ca, ib, cb]){
|
||||||
|
// XXX add pre-context...
|
||||||
|
// ...if changes are adjacent, then skip context...
|
||||||
|
yield ['=']
|
||||||
|
yield* ca
|
||||||
|
.map(function(change){
|
||||||
|
return ['-', ...change] })
|
||||||
|
yield* cb
|
||||||
|
.map(function(change){
|
||||||
|
return ['+', ...change] })
|
||||||
|
// XXX add post-context...
|
||||||
|
// ...if changes are adjacent, then skip context...
|
||||||
|
yield ['=']
|
||||||
|
}) }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// XXX move to test...
|
// XXX move to test...
|
||||||
@ -1034,15 +1063,29 @@ console.log([
|
|||||||
) ])
|
) ])
|
||||||
|
|
||||||
|
|
||||||
|
console.log('---')
|
||||||
|
|
||||||
|
console.dir(
|
||||||
|
[...toDiff(
|
||||||
|
keyValueDiff(
|
||||||
|
[['a', 'b'], 2, 3],
|
||||||
|
[1, 2, {x:1,y:2}],
|
||||||
|
))], {depth: null})
|
||||||
|
|
||||||
console.log('---')
|
console.log('---')
|
||||||
|
|
||||||
// XXX BUG: no change is detected here...
|
|
||||||
console.dir(
|
console.dir(
|
||||||
keyValueDiff(
|
keyValueDiff(
|
||||||
|
[,,,1,2,3],
|
||||||
|
[1,2,{x:1,y:2}],
|
||||||
|
), {depth: null})
|
||||||
|
console.log('')
|
||||||
|
// XXX BUG: the first change is wrong, it should be "add 3 empty"...
|
||||||
|
console.dir(
|
||||||
|
[...toDiff(
|
||||||
[,,,1,2,3],
|
[,,,1,2,3],
|
||||||
[1,2,3],
|
[1,2,{x:1,y:2}],
|
||||||
), {depth: null})
|
)], {depth: null})
|
||||||
|
|
||||||
console.log('---')
|
console.log('---')
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user