mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-28 18:40: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...
|
// 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 = {
|
||||||
|
|||||||
@ -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"
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user