mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-29 02:50:10 +00:00
more tweaking and experimenting...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
c6ec1b4a95
commit
7315e6f320
22
diff.js
22
diff.js
@ -1521,6 +1521,7 @@ Types.set(Array, {
|
|||||||
obj.length = A.length != B.length ? [A.length, B.length] : []
|
obj.length = A.length != B.length ? [A.length, B.length] : []
|
||||||
obj.items = this.typeCall(Array, 'items', diff, A, B, options)
|
obj.items = this.typeCall(Array, 'items', diff, A, B, options)
|
||||||
},
|
},
|
||||||
|
// XXX need to encode length into path/index...
|
||||||
walk: function(diff, func, path){
|
walk: function(diff, func, path){
|
||||||
var that = this
|
var that = this
|
||||||
var NONE = this.NONE
|
var NONE = this.NONE
|
||||||
@ -1563,6 +1564,10 @@ Types.set(Array, {
|
|||||||
|
|
||||||
// sub-array manipulation...
|
// sub-array manipulation...
|
||||||
if(i instanceof Array){
|
if(i instanceof Array){
|
||||||
|
// XXX remove .length support...
|
||||||
|
var li = i[1] == null ? change.length[0] : i[1]
|
||||||
|
var lj = j[1] == null ? change.length[1] : j[1]
|
||||||
|
|
||||||
i = i[0]
|
i = i[0]
|
||||||
j = j[0]
|
j = j[0]
|
||||||
|
|
||||||
@ -1571,16 +1576,16 @@ Types.set(Array, {
|
|||||||
obj.splice(j,
|
obj.splice(j,
|
||||||
'A' in change ?
|
'A' in change ?
|
||||||
change.A.length
|
change.A.length
|
||||||
: change.length[0],
|
: li,
|
||||||
...('B' in change ?
|
...('B' in change ?
|
||||||
change.B
|
change.B
|
||||||
// NOTE: this will insert a bunch of undefined's and
|
// NOTE: this will insert a bunch of undefined's and
|
||||||
// not empty slots, this we will need to cleanup
|
// not empty slots, this we will need to cleanup
|
||||||
// after (see below)...
|
// after (see below)...
|
||||||
: new Array(change.length[1])))
|
: new Array(lj)))
|
||||||
// cleanup...
|
// cleanup...
|
||||||
if(!('B' in change)){
|
if(!('B' in change)){
|
||||||
for(var n=j; n <= change.length[1] + j; n++){
|
for(var n=j; n <= lj + j; n++){
|
||||||
delete obj[n]
|
delete obj[n]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1657,6 +1662,7 @@ Types.set(Array, {
|
|||||||
items: function(diff, A, B, options){
|
items: function(diff, A, B, options){
|
||||||
var NONE = this.NONE
|
var NONE = this.NONE
|
||||||
var EMPTY = this.EMPTY
|
var EMPTY = this.EMPTY
|
||||||
|
|
||||||
var sections = getDiffSections(A, B, options.cmp)
|
var sections = getDiffSections(A, B, options.cmp)
|
||||||
|
|
||||||
// special case: last section set consists of sparse/empty arrays...
|
// special case: last section set consists of sparse/empty arrays...
|
||||||
@ -1682,6 +1688,7 @@ Types.set(Array, {
|
|||||||
// tail sections...
|
// tail sections...
|
||||||
// XXX hack???
|
// XXX hack???
|
||||||
// XXX should we use a different type/sub-type???
|
// XXX should we use a different type/sub-type???
|
||||||
|
// XXX need to encode length into path/index...
|
||||||
var tail = { type: 'Basic', }
|
var tail = { type: 'Basic', }
|
||||||
ta.filter(() => true).length > 0
|
ta.filter(() => true).length > 0
|
||||||
&& (tail.A = ta)
|
&& (tail.A = ta)
|
||||||
@ -1692,6 +1699,13 @@ Types.set(Array, {
|
|||||||
a = a.slice(0, l)
|
a = a.slice(0, l)
|
||||||
b = b.slice(0, l)
|
b = b.slice(0, l)
|
||||||
|
|
||||||
|
// Builds:
|
||||||
|
// [
|
||||||
|
// [i, j, diff],
|
||||||
|
// ...
|
||||||
|
// [[i], [i], tail],
|
||||||
|
// ]
|
||||||
|
// XXX need to encode length into path/index...
|
||||||
return zip(
|
return zip(
|
||||||
function(n, elems){
|
function(n, elems){
|
||||||
return [
|
return [
|
||||||
@ -1719,7 +1733,7 @@ Types.set(Array, {
|
|||||||
] },
|
] },
|
||||||
a, b)
|
a, b)
|
||||||
// clear matching stuff...
|
// clear matching stuff...
|
||||||
.filter(function(e){
|
.filter(function(e){
|
||||||
return e[2] != null})
|
return e[2] != null})
|
||||||
// splice array sub-sections...
|
// splice array sub-sections...
|
||||||
.concat(ta.length + tb.length > 0 ?
|
.concat(ta.length + tb.length > 0 ?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user