mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-28 18:40:09 +00:00
notes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
85bbacc1c2
commit
f9d81c2bac
80
diff2.js
80
diff2.js
@ -94,15 +94,47 @@ module.CONTENT =
|
|||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
// XXX OFFSET: should we also store index???
|
// XXX OFFSET: should we also store .index???
|
||||||
var Offset =
|
var Offset =
|
||||||
module.Offset =
|
module.Offset =
|
||||||
object.Constructor('Offset', {
|
object.Constructor('Offset', {
|
||||||
|
value: undefined,
|
||||||
|
index: undefined,
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
toString: function(){
|
||||||
|
//return `Offset(${this, value})` },
|
||||||
|
return this.index == null ?
|
||||||
|
`Offset(${this.value})`
|
||||||
|
: `Offset(${this.value}, ${this.index})` },
|
||||||
|
// XXX
|
||||||
|
valueOf: function(){
|
||||||
|
return this.value },
|
||||||
|
// XXX should we consistency check that index is >= offset ???
|
||||||
__init__: function(value, index){
|
__init__: function(value, index){
|
||||||
this.value = value
|
this.value = value
|
||||||
this.index = index }, })
|
this.index = index },
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// XXX revise...
|
||||||
|
var Path =
|
||||||
|
module.Path =
|
||||||
|
object.Constructor('Path', Array, {
|
||||||
|
__str: undefined,
|
||||||
|
get str(){
|
||||||
|
return this.__str
|
||||||
|
|| (this.__str = path2str(this)) },
|
||||||
|
set str(value){
|
||||||
|
delete this.__str
|
||||||
|
this.splice(0, this.length, ...str2path(value)) },
|
||||||
|
|
||||||
|
valueOf: function(){
|
||||||
|
return this.str },
|
||||||
|
toString: function(){
|
||||||
|
return 'Path: '+ this.valueOf() },
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
@ -253,6 +285,9 @@ object.Constructor('Walk', {
|
|||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
// XXX PATH: might be a good idea to use a Path(..) object instead of
|
||||||
|
// current list/string paths and simply use both as a way to
|
||||||
|
// serialize...
|
||||||
// XXX we can treat the output as a stack language...
|
// XXX we can treat the output as a stack language...
|
||||||
// ...need to clear out unneeded stuff...
|
// ...need to clear out unneeded stuff...
|
||||||
// XXX add function support...
|
// XXX add function support...
|
||||||
@ -762,30 +797,25 @@ function(A, B, cmp){
|
|||||||
return gaps }, []) }
|
return gaps }, []) }
|
||||||
|
|
||||||
|
|
||||||
// XXX if two sub-trees are different, to 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???
|
||||||
// XXX at this point array indexes are treated as changes, i.e. if we
|
// XXX might be a good idea to strip out (optionally) differences within
|
||||||
// insert an item into an array, this effectively changes all other
|
// a container that differ only in container path, i.e.:
|
||||||
// items (shifting their indexes by the number of items inserted)...
|
// /a/b/:4/x 123
|
||||||
// ...need to treat this gracefully...
|
// and
|
||||||
// we can:
|
// /a/b/:1/x 123
|
||||||
// - ignore array index???
|
// are not different...
|
||||||
// ...to do this we need to know object type per element
|
// example:
|
||||||
// compared...
|
// // this will list that every element within the nested array
|
||||||
// - handle item shifts gracefully...
|
// // is different...
|
||||||
// - diff recursively instead of flat...
|
// keyValueDiff(
|
||||||
// XXX another way to approach this is to treat indexes in a relative
|
// [ ,, [1,2,3] ],
|
||||||
// manner, i.e. keep track of relative order of elements...
|
// [ [1,2,3] ])
|
||||||
// e.g. if we insert a sub-array then all the elements after it are
|
// ...would be nice to do this as early as possible, possibly even
|
||||||
// simply shifted, that is, their relative order is maintained...
|
// within commonSections(..)
|
||||||
// ...this is already tracked by diffSections(..) but after
|
// ...can this be done by simply comparing the last path element
|
||||||
// handler(..) arrays are more like hashes, and we need to
|
// for any contained element???
|
||||||
// account for this....
|
|
||||||
// XXX yet another approach to this is to work in two stages:
|
|
||||||
// 1) diff ignoring keys...
|
|
||||||
// 2) selectively match keys...
|
|
||||||
// ...need to test how complex this will be...
|
|
||||||
//
|
|
||||||
var keyValueDiff =
|
var keyValueDiff =
|
||||||
function(A, B){
|
function(A, B){
|
||||||
return diffSections(
|
return diffSections(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user