mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-29 02:50:10 +00:00
notes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
eb232e1c99
commit
c6ec1b4a95
106
diff.js
106
diff.js
@ -622,6 +622,13 @@ object.makeConstructor('OF', Object.assign(new LogicType(), {
|
|||||||
// // NOTE: if both of the array items are arrays
|
// // NOTE: if both of the array items are arrays
|
||||||
// // it means that we are splicing array
|
// // it means that we are splicing array
|
||||||
// // sections instead of array elements...
|
// // sections instead of array elements...
|
||||||
|
// // XXX should this be:
|
||||||
|
// // [
|
||||||
|
// // null | index | [index, length],
|
||||||
|
// // null | index | [index, length],
|
||||||
|
// // ]
|
||||||
|
// // ...this way would will be able to drop
|
||||||
|
// // the .length...
|
||||||
// path: [<key>, ...],
|
// path: [<key>, ...],
|
||||||
//
|
//
|
||||||
// // values in A and B...
|
// // values in A and B...
|
||||||
@ -1071,8 +1078,6 @@ module.Types = {
|
|||||||
return change.B
|
return change.B
|
||||||
}
|
}
|
||||||
|
|
||||||
var type = change.type || Object
|
|
||||||
|
|
||||||
var parent
|
var parent
|
||||||
var parent_key
|
var parent_key
|
||||||
var target = change.path
|
var target = change.path
|
||||||
@ -1084,6 +1089,8 @@ module.Types = {
|
|||||||
}, obj)
|
}, obj)
|
||||||
var key = change.path[change.path.length-1]
|
var key = change.path[change.path.length-1]
|
||||||
|
|
||||||
|
var type = change.type || Object
|
||||||
|
|
||||||
// call the actual patch...
|
// call the actual patch...
|
||||||
var res = that.typeCall(type, 'patch', target, key, change, obj, options)
|
var res = that.typeCall(type, 'patch', target, key, change, obj, options)
|
||||||
|
|
||||||
@ -1143,8 +1150,6 @@ module.Types = {
|
|||||||
return change.B
|
return change.B
|
||||||
}
|
}
|
||||||
|
|
||||||
var type = change.type || Object
|
|
||||||
|
|
||||||
var parent
|
var parent
|
||||||
var parent_key
|
var parent_key
|
||||||
var target = change.path
|
var target = change.path
|
||||||
@ -1156,8 +1161,14 @@ module.Types = {
|
|||||||
}, obj)
|
}, obj)
|
||||||
var key = change.path[change.path.length-1]
|
var key = change.path[change.path.length-1]
|
||||||
|
|
||||||
|
var type = change.type || Object
|
||||||
|
|
||||||
// call the actual patch...
|
// call the actual patch...
|
||||||
var res = that.typeCall(type, '_walk', target, key, change, func, options)
|
// XXX the key can be contextual so we either need to pass
|
||||||
|
// down the context (change and what side we are
|
||||||
|
// looking from, A or B) or make the keys context-free
|
||||||
|
// and handle them here...
|
||||||
|
var res = that.typeCall(type, 'get', target, key)
|
||||||
|
|
||||||
// replace the parent value...
|
// replace the parent value...
|
||||||
if(parent){
|
if(parent){
|
||||||
@ -1444,16 +1455,12 @@ Types.set(Object, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// XXX EXPERIMENTAL...
|
// XXX EXPERIMENTAL...
|
||||||
_walk: function(obj, key, change, func, ...rest){
|
get: function(obj, key){
|
||||||
// object attr...
|
return typeof(key) == typeof('str') ?
|
||||||
if(typeof(key) == typeof('str')){
|
obj[key]
|
||||||
return func(obj, key, change)
|
: this.typeCall(Array, 'get', obj, key) },
|
||||||
|
set: function(obj, key, value){
|
||||||
// array item...
|
// XXX
|
||||||
// XXX should this make this decision???
|
|
||||||
} else {
|
|
||||||
return this.typeCall(Array, '_walk', obj, key, change, func, ...rest)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// part handlers...
|
// part handlers...
|
||||||
@ -1645,70 +1652,7 @@ Types.set(Array, {
|
|||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
_walk: function(obj, key, change, func, ...rest){
|
|
||||||
var i = key instanceof Array ? key[0] : key
|
|
||||||
var j = key instanceof Array ? key[1] : key
|
|
||||||
|
|
||||||
// sub-array manipulation...
|
|
||||||
if(i instanceof Array){
|
|
||||||
i = i[0]
|
|
||||||
j = j[0]
|
|
||||||
|
|
||||||
// XXX check compatibility...
|
|
||||||
|
|
||||||
obj.splice(j,
|
|
||||||
'A' in change ?
|
|
||||||
change.A.length
|
|
||||||
: change.length[0],
|
|
||||||
...('B' in change ?
|
|
||||||
change.B
|
|
||||||
// NOTE: this will insert a bunch of undefined's and
|
|
||||||
// not empty slots, this we will need to cleanup
|
|
||||||
// after (see below)...
|
|
||||||
: new Array(change.length[1])))
|
|
||||||
// cleanup...
|
|
||||||
if(!('B' in change)){
|
|
||||||
for(var n=j; n <= change.length[1] + j; n++){
|
|
||||||
delete obj[n]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// item manipulation...
|
|
||||||
} else {
|
|
||||||
if(i == null){
|
|
||||||
// XXX this will mess up the indexing for the rest of
|
|
||||||
// item removals...
|
|
||||||
obj.splice(j, 0, change.B)
|
|
||||||
|
|
||||||
} else if(j == null){
|
|
||||||
// obj explicitly empty...
|
|
||||||
if('B' in change && this.cmp(change.B, EMPTY)){
|
|
||||||
delete obj[i]
|
|
||||||
|
|
||||||
// splice out obj...
|
|
||||||
} else if(!('B' in change) || this.cmp(change.B, NONE)){
|
|
||||||
// NOTE: this does not affect the later elements
|
|
||||||
// indexing as it essentially shifts the
|
|
||||||
// indexes to their obj state for next
|
|
||||||
// changes...
|
|
||||||
obj.splice(i, 1)
|
|
||||||
|
|
||||||
// XXX
|
|
||||||
} else {
|
|
||||||
// XXX
|
|
||||||
console.log('!!!!!!!!!!')
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if(i == j){
|
|
||||||
obj[j] = change.B
|
|
||||||
|
|
||||||
} else {
|
|
||||||
obj[j] = change.B
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return obj
|
|
||||||
},
|
|
||||||
// part handlers...
|
// part handlers...
|
||||||
items: function(diff, A, B, options){
|
items: function(diff, A, B, options){
|
||||||
var NONE = this.NONE
|
var NONE = this.NONE
|
||||||
@ -1872,6 +1816,12 @@ Types.set('Text', {
|
|||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// XXX EXPERIMENTAL...
|
||||||
|
get: function(obj, key){
|
||||||
|
},
|
||||||
|
set: function(obj, key, value){
|
||||||
|
},
|
||||||
|
|
||||||
// replace all the cached text items...
|
// replace all the cached text items...
|
||||||
postPatch: function(res){
|
postPatch: function(res){
|
||||||
var cache = this._text_cache = this._text_cache || {}
|
var cache = this._text_cache = this._text_cache || {}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user