cleanup + some tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-08-01 17:45:09 +03:00
parent 80e8f9d0f3
commit 15d6189e10
2 changed files with 16 additions and 10 deletions

View File

@ -32,6 +32,7 @@ XXX
- Full JSON *diff* support - Full JSON *diff* support
- Support for JavaScript objects without restrictions - Support for JavaScript objects without restrictions
- *Text diff* support - *Text diff* support
- ~~Optional attribute order support~~ (not done yet)
- Configurable and extensible implementation - Configurable and extensible implementation
- As simple as possible - As simple as possible
@ -132,7 +133,7 @@ Shorter strings or strings containing just a single line are treated as *basic*
// //
// NOTE: a string must also contain at least one \n to be text // NOTE: a string must also contain at least one \n to be text
// diffed... // diffed...
min_text_length: 1000 | -1, min_text_length: 100 | -1,
// If true, disable attribute diff for non Object's... // If true, disable attribute diff for non Object's...
// //
@ -267,7 +268,7 @@ ExtendedDiff.types.set('SomeType', {
// .check(obj[, options]) // .check(obj[, options])
// -> bool // -> bool
// //
check: function(obj, options){ compatible: function(obj, options){
// ... // ...
}, },

21
diff.js
View File

@ -697,8 +697,8 @@ module.Types = {
// explicit checkers have priority over instance tests... // explicit checkers have priority over instance tests...
for(var t of types){ for(var t of types){
var h = this.get(t) var h = this.get(t)
if(h.check if(h.compatible
&& h.check(A, options)){ && h.compatible(A, options)){
type = t type = t
break break
} }
@ -1005,8 +1005,13 @@ module.Types = {
// Check if diff is applicable to obj... // Check if diff is applicable to obj...
// //
// XXX should this return a diff???
// XXX need a custom check for custom handler...
// ...we also have a name clash whit .check(..) that checks if
// the object type is compatible to handler...
// XXX EXPERIMENTAL...
check: function(diff, obj, options){ check: function(diff, obj, options){
// XXX // XXX try and use .walk(..) + custom handlers for custom types...
}, },
} }
@ -1049,10 +1054,10 @@ module.Types = {
// //
// // Check if obj is compatible (optional)... // // Check if obj is compatible (optional)...
// // // //
// // .check(obj[, options]) // // .compatible(obj[, options])
// // -> bool // // -> bool
// // // //
// check: function(obj, options){ // compatible: function(obj, options){
// .. // ..
// }, // },
// //
@ -1146,7 +1151,7 @@ Types.set('Basic', {
priority: 50, priority: 50,
no_attributes: true, no_attributes: true,
check: function(obj, options){ compatible: function(obj, options){
return typeof(obj) != 'object' }, return typeof(obj) != 'object' },
handle: function(obj, diff, A, B, options){ handle: function(obj, diff, A, B, options){
;(!options.keep_none && A === NONE) ;(!options.keep_none && A === NONE)
@ -1485,7 +1490,7 @@ Types.set('Text', {
priority: 100, priority: 100,
no_attributes: true, no_attributes: true,
check: function(obj, options){ compatible: function(obj, options){
options = options || {} options = options || {}
min = options.min_text_length || MIN_TEXT_LENGTH min = options.min_text_length || MIN_TEXT_LENGTH
return typeof(obj) == typeof('str') return typeof(obj) == typeof('str')
@ -1659,7 +1664,7 @@ Types.set(LogicType, {
// //
// // add a new synthetic type... // // add a new synthetic type...
// ExtendedDiff.types.set('SomeOtherType', { // ExtendedDiff.types.set('SomeOtherType', {
// check: function(..){ .. }, // compatible: function(..){ .. },
// ... // ...
// }) // })
// //