mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-28 10:30:09 +00:00
more experimenting...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
1fbe2a7b93
commit
31c96dd325
33
diff.js
33
diff.js
@ -12,6 +12,18 @@ var object = require('ig-object')
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
// XXX General ToDo:
|
||||
// - revise architecture...
|
||||
// - revise name -- this contains two parts:
|
||||
// 1. diff / patch and friends
|
||||
// 2. cmp and patterns
|
||||
// we need the name to be short and descriptive, possible
|
||||
// candidates:
|
||||
// - objdiff / object-diff
|
||||
// - diffcmp / diff-cmp
|
||||
// - compare
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------------
|
||||
// Helpers...
|
||||
|
||||
@ -216,6 +228,8 @@ var EMPTY = {type: 'EMPTY_PLACEHOLDER'}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Logic patterns...
|
||||
// XXX we should handle LogicType-LogicType comparisons in a graceful
|
||||
// way...
|
||||
// XXX should this also include the above placeholders, especially ANY???
|
||||
|
||||
var LogicTypeClassPrototype = {
|
||||
@ -236,22 +250,19 @@ object.makeConstructor('LogicType',
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// ANY...
|
||||
// XXX should this be a singleton???
|
||||
var ANYPrototype = {
|
||||
cmp: function(obj, cmp){
|
||||
return true
|
||||
},
|
||||
return true },
|
||||
}
|
||||
ANYPrototype.__proto__ = LogicTypePrototype
|
||||
|
||||
var ANY =
|
||||
module.ANY =
|
||||
object.makeConstructor('ANY',
|
||||
ANYPrototype)
|
||||
module.ANY = new (object.makeConstructor('ANY', ANYPrototype))()
|
||||
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// OR...
|
||||
// XXX does not work with diff at the moment...
|
||||
var ORPrototype = {
|
||||
cmp: function(obj, cmp){
|
||||
cmp = cmp || function(a, b){
|
||||
@ -277,6 +288,7 @@ object.makeConstructor('OR',
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// AND...
|
||||
// XXX does not work with diff at the moment...
|
||||
var ANDPrototype = {
|
||||
cmp: function(obj, cmp){
|
||||
cmp = cmp || function(a, b){
|
||||
@ -702,7 +714,7 @@ var Types = {
|
||||
diff: function(A, B, options, cache){
|
||||
var that = this
|
||||
options = options ? Object.create(options) : {}
|
||||
options.cmp = options.cmp
|
||||
var cmp = options.cmp = options.cmp
|
||||
|| function(a, b){
|
||||
return a === b
|
||||
|| a == b
|
||||
@ -711,8 +723,10 @@ var Types = {
|
||||
|| b === that.ANY
|
||||
// logic patterns...
|
||||
// XXX not final...
|
||||
|| (a instanceof LogicType && a.cmp(b, cmp))
|
||||
|| (b instanceof LogicType && b.cmp(a, cmp))
|
||||
|| (a instanceof LogicType
|
||||
&& a.cmp(b, cmp))
|
||||
|| (b instanceof LogicType
|
||||
&& b.cmp(a, cmp))
|
||||
// diff...
|
||||
// NOTE: diff(..) is in closure, so we do not need to
|
||||
// pass options and cache down.
|
||||
@ -1449,6 +1463,7 @@ function(diff, obj, options, types){
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// XXX EXPERIMENTAL...
|
||||
|
||||
// XXX
|
||||
var DiffClassPrototype = {
|
||||
|
||||
@ -1,13 +1,8 @@
|
||||
{
|
||||
"name": "object-diff",
|
||||
"name": "diff-cmp",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"main": "diff.js",
|
||||
"author": {
|
||||
"name": "Alex A. Naanou",
|
||||
"email": "alex.nanou@gmail.com",
|
||||
"url": "https://github.com/flynx"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user