mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-29 02:50:10 +00:00
minor refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
db363aa47c
commit
12f11f8a93
76
diff.js
76
diff.js
@ -371,9 +371,9 @@ var LogicTypePrototype = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var LogicType =
|
var Pattern =
|
||||||
module.LogicType =
|
module.Pattern =
|
||||||
object.makeConstructor('LogicType',
|
object.makeConstructor('Pattern',
|
||||||
LogicTypeClassPrototype,
|
LogicTypeClassPrototype,
|
||||||
LogicTypePrototype)
|
LogicTypePrototype)
|
||||||
|
|
||||||
@ -573,7 +573,7 @@ var L = module.L = ARRAY
|
|||||||
// Will compare as true to anything but .value...
|
// Will compare as true to anything but .value...
|
||||||
var NOT =
|
var NOT =
|
||||||
module.NOT =
|
module.NOT =
|
||||||
object.makeConstructor('NOT', Object.assign(Object.create(LogicType.prototype), {
|
object.makeConstructor('NOT', Object.assign(Object.create(Pattern.prototype), {
|
||||||
__cmp__: function(obj, cmp, context){
|
__cmp__: function(obj, cmp, context){
|
||||||
return !cmp(this.value, obj, context) },
|
return !cmp(this.value, obj, context) },
|
||||||
__init__: function(value){
|
__init__: function(value){
|
||||||
@ -585,7 +585,7 @@ object.makeConstructor('NOT', Object.assign(Object.create(LogicType.prototype),
|
|||||||
// Will compare as true if one of the .members compares as true...
|
// Will compare as true if one of the .members compares as true...
|
||||||
var OR =
|
var OR =
|
||||||
module.OR =
|
module.OR =
|
||||||
object.makeConstructor('OR', Object.assign(Object.create(LogicType.prototype), {
|
object.makeConstructor('OR', Object.assign(Object.create(Pattern.prototype), {
|
||||||
__cmp__: function(obj, cmp, context){
|
__cmp__: function(obj, cmp, context){
|
||||||
for(var m of this.members){
|
for(var m of this.members){
|
||||||
if(cmp(m, obj, context)){
|
if(cmp(m, obj, context)){
|
||||||
@ -603,7 +603,7 @@ object.makeConstructor('OR', Object.assign(Object.create(LogicType.prototype), {
|
|||||||
// Will compare as true if all of the .members compare as true...
|
// Will compare as true if all of the .members compare as true...
|
||||||
var AND =
|
var AND =
|
||||||
module.AND =
|
module.AND =
|
||||||
object.makeConstructor('AND', Object.assign(Object.create(LogicType.prototype), {
|
object.makeConstructor('AND', Object.assign(Object.create(Pattern.prototype), {
|
||||||
__cmp__: function(obj, cmp, context){
|
__cmp__: function(obj, cmp, context){
|
||||||
for(var m of this.members){
|
for(var m of this.members){
|
||||||
if(!cmp(m, obj, context)){
|
if(!cmp(m, obj, context)){
|
||||||
@ -624,7 +624,7 @@ object.makeConstructor('AND', Object.assign(Object.create(LogicType.prototype),
|
|||||||
// -> false
|
// -> false
|
||||||
var CONTEXT =
|
var CONTEXT =
|
||||||
module.CONTEXT =
|
module.CONTEXT =
|
||||||
object.makeConstructor('CONTEXT', Object.assign(Object.create(LogicType.prototype), {
|
object.makeConstructor('CONTEXT', Object.assign(Object.create(Pattern.prototype), {
|
||||||
__cmp__: function(obj, cmp, context){
|
__cmp__: function(obj, cmp, context){
|
||||||
return cmp(this.pattern, obj) },
|
return cmp(this.pattern, obj) },
|
||||||
__init__: function(pattern){
|
__init__: function(pattern){
|
||||||
@ -635,7 +635,7 @@ object.makeConstructor('CONTEXT', Object.assign(Object.create(LogicType.prototyp
|
|||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
var VAR =
|
var VAR =
|
||||||
module.VAR =
|
module.VAR =
|
||||||
object.makeConstructor('VAR', Object.assign(Object.create(LogicType.prototype), {
|
object.makeConstructor('VAR', Object.assign(Object.create(Pattern.prototype), {
|
||||||
__cmp__: function(obj, cmp, context){
|
__cmp__: function(obj, cmp, context){
|
||||||
var context = context || this.context().__context__
|
var context = context || this.context().__context__
|
||||||
var ns = context.ns = context.ns || {}
|
var ns = context.ns = context.ns || {}
|
||||||
@ -678,7 +678,7 @@ object.makeConstructor('LIKE', Object.assign(Object.create(VAR.prototype), {
|
|||||||
// TEST(func) == L iff func(L) is true.
|
// TEST(func) == L iff func(L) is true.
|
||||||
var TEST =
|
var TEST =
|
||||||
module.TEST =
|
module.TEST =
|
||||||
object.makeConstructor('TEST', Object.assign(Object.create(LogicType.prototype), {
|
object.makeConstructor('TEST', Object.assign(Object.create(Pattern.prototype), {
|
||||||
__cmp__: function(obj, cmp, context){
|
__cmp__: function(obj, cmp, context){
|
||||||
return this.func(obj, cmp, context) },
|
return this.func(obj, cmp, context) },
|
||||||
__init__: function(func){
|
__init__: function(func){
|
||||||
@ -695,7 +695,7 @@ object.makeConstructor('TEST', Object.assign(Object.create(LogicType.prototype),
|
|||||||
// NOTE: to test if a key exists use AT(key)
|
// NOTE: to test if a key exists use AT(key)
|
||||||
var IN =
|
var IN =
|
||||||
module.IN =
|
module.IN =
|
||||||
object.makeConstructor('IN', Object.assign(Object.create(LogicType.prototype), {
|
object.makeConstructor('IN', Object.assign(Object.create(Pattern.prototype), {
|
||||||
// XXX make this a break-on-match and not a go-through-the-whole-thing
|
// XXX make this a break-on-match and not a go-through-the-whole-thing
|
||||||
// XXX should we check inherited stuff???
|
// XXX should we check inherited stuff???
|
||||||
__cmp__: function(obj, cmp, context){
|
__cmp__: function(obj, cmp, context){
|
||||||
@ -743,7 +743,7 @@ object.makeConstructor('IN', Object.assign(Object.create(LogicType.prototype), {
|
|||||||
// XXX support Maps, ...
|
// XXX support Maps, ...
|
||||||
var AT =
|
var AT =
|
||||||
module.AT =
|
module.AT =
|
||||||
object.makeConstructor('AT', Object.assign(Object.create(LogicType.prototype), {
|
object.makeConstructor('AT', Object.assign(Object.create(Pattern.prototype), {
|
||||||
__cmp__: function(obj, cmp, context){
|
__cmp__: function(obj, cmp, context){
|
||||||
var key = this.key instanceof Array ? this.key : [this.key]
|
var key = this.key instanceof Array ? this.key : [this.key]
|
||||||
var value = this.value
|
var value = this.value
|
||||||
@ -755,7 +755,7 @@ object.makeConstructor('AT', Object.assign(Object.create(LogicType.prototype), {
|
|||||||
return o == null ?
|
return o == null ?
|
||||||
[]
|
[]
|
||||||
// pattern key,,,
|
// pattern key,,,
|
||||||
: k instanceof LogicType ?
|
: k instanceof Pattern ?
|
||||||
[...getAllKeys(o)]
|
[...getAllKeys(o)]
|
||||||
.filter(function(n){
|
.filter(function(n){
|
||||||
return cmp(k, n, context) })
|
return cmp(k, n, context) })
|
||||||
@ -796,7 +796,7 @@ object.makeConstructor('AT', Object.assign(Object.create(LogicType.prototype), {
|
|||||||
// XXX ORDERED(A, B, ..) == L iff A is before B, B is before C, ... etc.
|
// XXX ORDERED(A, B, ..) == L iff A is before B, B is before C, ... etc.
|
||||||
var ORDERED =
|
var ORDERED =
|
||||||
module.ORDERED =
|
module.ORDERED =
|
||||||
object.makeConstructor('ORDERED', Object.assign(Object.create(LogicType.prototype), {
|
object.makeConstructor('ORDERED', Object.assign(Object.create(Pattern.prototype), {
|
||||||
__cmp__: function(obj, cmp){
|
__cmp__: function(obj, cmp){
|
||||||
// XXX
|
// XXX
|
||||||
},
|
},
|
||||||
@ -809,7 +809,7 @@ object.makeConstructor('ORDERED', Object.assign(Object.create(LogicType.prototyp
|
|||||||
// XXX ADJACENT(A, B, ..) == L iff A directly before B, B directly before C, ...
|
// XXX ADJACENT(A, B, ..) == L iff A directly before B, B directly before C, ...
|
||||||
var ADJACENT =
|
var ADJACENT =
|
||||||
module.ADJACENT =
|
module.ADJACENT =
|
||||||
object.makeConstructor('ADJACENT', Object.assign(Object.create(LogicType.prototype), {
|
object.makeConstructor('ADJACENT', Object.assign(Object.create(Pattern.prototype), {
|
||||||
__cmp__: function(obj, cmp){
|
__cmp__: function(obj, cmp){
|
||||||
// XXX
|
// XXX
|
||||||
},
|
},
|
||||||
@ -824,7 +824,7 @@ object.makeConstructor('ADJACENT', Object.assign(Object.create(LogicType.prototy
|
|||||||
// on matching...
|
// on matching...
|
||||||
var OF =
|
var OF =
|
||||||
module.OF =
|
module.OF =
|
||||||
object.makeConstructor('OF', Object.assign(Object.create(LogicType.prototype), {
|
object.makeConstructor('OF', Object.assign(Object.create(Pattern.prototype), {
|
||||||
__cmp__: function(obj, cmp){
|
__cmp__: function(obj, cmp){
|
||||||
// XXX
|
// XXX
|
||||||
},
|
},
|
||||||
@ -1425,9 +1425,9 @@ module.Types = {
|
|||||||
|| a === that.ANY
|
|| a === that.ANY
|
||||||
|| b === that.ANY
|
|| b === that.ANY
|
||||||
// logic patterns...
|
// logic patterns...
|
||||||
|| (a instanceof LogicType
|
|| (a instanceof Pattern
|
||||||
&& a.cmp(b, cmp, context))
|
&& a.cmp(b, cmp, context))
|
||||||
|| (b instanceof LogicType
|
|| (b instanceof Pattern
|
||||||
&& b.cmp(a, cmp, context)) }
|
&& b.cmp(a, cmp, context)) }
|
||||||
// deep compare...
|
// deep compare...
|
||||||
var cmp = options.cmp = options.cmp
|
var cmp = options.cmp = options.cmp
|
||||||
@ -1440,8 +1440,8 @@ module.Types = {
|
|||||||
|| (diff(a, b) == null) }
|
|| (diff(a, b) == null) }
|
||||||
// cache...
|
// cache...
|
||||||
context = context
|
context = context
|
||||||
|| (A instanceof LogicType ? A.context().__context__
|
|| (A instanceof Pattern ? A.context().__context__
|
||||||
: B instanceof LogicType ? B.context().__context__
|
: B instanceof Pattern ? B.context().__context__
|
||||||
: {})
|
: {})
|
||||||
cache = context.cache = context.cache || new Map()
|
cache = context.cache = context.cache || new Map()
|
||||||
// cached diff...
|
// cached diff...
|
||||||
@ -1514,9 +1514,9 @@ module.Types = {
|
|||||||
|| a === that.ANY
|
|| a === that.ANY
|
||||||
|| b === that.ANY
|
|| b === that.ANY
|
||||||
// logic patterns...
|
// logic patterns...
|
||||||
|| (a instanceof LogicType
|
|| (a instanceof Pattern
|
||||||
&& a.cmp(b))
|
&& a.cmp(b))
|
||||||
|| (b instanceof LogicType
|
|| (b instanceof Pattern
|
||||||
&& b.cmp(a)) }
|
&& b.cmp(a)) }
|
||||||
|
|
||||||
options.cmp = cmp
|
options.cmp = cmp
|
||||||
@ -2432,6 +2432,24 @@ Types.set(Array, {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
/*/ Pattern...
|
||||||
|
// XXX need to accompany this with a walk pattern protocol....
|
||||||
|
// XXX show the actual part of the pattern we got a mismatch...
|
||||||
|
Types.set(Pattern, {
|
||||||
|
handle: function(obj, diff, A, B, options){
|
||||||
|
// XXX
|
||||||
|
}
|
||||||
|
walk: function(diff, func, path){
|
||||||
|
// XXX
|
||||||
|
},
|
||||||
|
reverse: function(change){
|
||||||
|
// XXX
|
||||||
|
},
|
||||||
|
})
|
||||||
|
//*/
|
||||||
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
// XXX add JS types like Map, Set, ...
|
// XXX add JS types like Map, Set, ...
|
||||||
// XXX Q: can Map/Set be supported???
|
// XXX Q: can Map/Set be supported???
|
||||||
@ -2539,22 +2557,6 @@ Types.set('Text', {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
// LogicType...
|
|
||||||
/*/ XXX show the actual part of the pattern we got a mismatch...
|
|
||||||
Types.set(LogicType, {
|
|
||||||
handle: function(obj, diff, A, B, options){
|
|
||||||
// XXX
|
|
||||||
}
|
|
||||||
walk: function(diff, func, path){
|
|
||||||
// XXX
|
|
||||||
},
|
|
||||||
reverse: function(change){
|
|
||||||
// XXX
|
|
||||||
},
|
|
||||||
})
|
|
||||||
//*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user