more experimenting...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-07-27 02:11:38 +03:00
parent 1fbe2a7b93
commit 31c96dd325
2 changed files with 26 additions and 16 deletions

35
diff.js
View File

@ -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... // Helpers...
@ -216,6 +228,8 @@ var EMPTY = {type: 'EMPTY_PLACEHOLDER'}
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// Logic patterns... // Logic patterns...
// XXX we should handle LogicType-LogicType comparisons in a graceful
// way...
// XXX should this also include the above placeholders, especially ANY??? // XXX should this also include the above placeholders, especially ANY???
var LogicTypeClassPrototype = { var LogicTypeClassPrototype = {
@ -236,22 +250,19 @@ object.makeConstructor('LogicType',
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// ANY... // ANY...
// XXX should this be a singleton???
var ANYPrototype = { var ANYPrototype = {
cmp: function(obj, cmp){ cmp: function(obj, cmp){
return true return true },
},
} }
ANYPrototype.__proto__ = LogicTypePrototype ANYPrototype.__proto__ = LogicTypePrototype
var ANY = var ANY =
module.ANY = module.ANY = new (object.makeConstructor('ANY', ANYPrototype))()
object.makeConstructor('ANY',
ANYPrototype)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// OR... // OR...
// XXX does not work with diff at the moment...
var ORPrototype = { var ORPrototype = {
cmp: function(obj, cmp){ cmp: function(obj, cmp){
cmp = cmp || function(a, b){ cmp = cmp || function(a, b){
@ -277,6 +288,7 @@ object.makeConstructor('OR',
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// AND... // AND...
// XXX does not work with diff at the moment...
var ANDPrototype = { var ANDPrototype = {
cmp: function(obj, cmp){ cmp: function(obj, cmp){
cmp = cmp || function(a, b){ cmp = cmp || function(a, b){
@ -702,7 +714,7 @@ var Types = {
diff: function(A, B, options, cache){ diff: function(A, B, options, cache){
var that = this var that = this
options = options ? Object.create(options) : {} options = options ? Object.create(options) : {}
options.cmp = options.cmp var cmp = options.cmp = options.cmp
|| function(a, b){ || function(a, b){
return a === b return a === b
|| a == b || a == b
@ -711,8 +723,10 @@ var Types = {
|| b === that.ANY || b === that.ANY
// logic patterns... // logic patterns...
// XXX not final... // XXX not final...
|| (a instanceof LogicType && a.cmp(b, cmp)) || (a instanceof LogicType
|| (b instanceof LogicType && b.cmp(a, cmp)) && a.cmp(b, cmp))
|| (b instanceof LogicType
&& b.cmp(a, cmp))
// diff... // diff...
// NOTE: diff(..) is in closure, so we do not need to // NOTE: diff(..) is in closure, so we do not need to
// pass options and cache down. // pass options and cache down.
@ -1449,6 +1463,7 @@ function(diff, obj, options, types){
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// XXX EXPERIMENTAL...
// XXX // XXX
var DiffClassPrototype = { var DiffClassPrototype = {

View File

@ -1,13 +1,8 @@
{ {
"name": "object-diff", "name": "diff-cmp",
"version": "0.0.1", "version": "0.0.1",
"description": "", "description": "",
"main": "diff.js", "main": "diff.js",
"author": {
"name": "Alex A. Naanou",
"email": "alex.nanou@gmail.com",
"url": "https://github.com/flynx"
},
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },