more tweaks...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-09-05 03:24:41 +03:00
parent a4a525b84a
commit 9e76bf867b
2 changed files with 35 additions and 1 deletions

View File

@ -15,6 +15,7 @@
- [Diff](#diff)
- [Diff class API](#diff-class-api)
- [Diff object API](#diff-object-api)
- [Shorthands and functions](#shorthands-and-functions)
- [Supported JavaScript objects](#supported-javascript-objects)
- [Extended 'Text' object support](#extended-text-object-support)
- [Options](#options)
@ -267,7 +268,10 @@ var diff = new Diff(A, B)
`Diff.cmp(A, B) -> bool`
Deep compare `A` to `B`.
`Diff.clone(<title>)`
`Diff.vars(pattern, A) -> obj`
Get variable values defined (via `VAR`/`LIKE`) in `pattern` matching corresponding values in `obj`.
`Diff.clone(title)`
Clone the `Diff` constructor, useful for extending or tweaking the type handlers (see: [Extending](#extending-diff) below).
`Diff.fromJSON(json) -> diff`
@ -313,6 +317,24 @@ Return the *parent diff* that was used to generate the current *child diff* or t
Serialize the *diff* to JSON. Note that the output may or may not be JSON compatible depending on the inputs.
### Shorthands and functions
`cmp(A, B) -> bool`
Deep compare `A` and `B`.
This is a shorthand to: `Diff.cmp(A, B) -> bool`
`patch(diff, A) -> A'`
Apply changes in `diff` to `A` (*patch*).
This is a shorthand to: `diff.patch(A) -> A'`
`vars(pattern, A) -> obj`
Get variable values defined (via `VAR`/`LIKE`) in `pattern` matching corresponding values in `obj`.
This is a shorthand to: `Diff.vars(pattern, B) -> obj`
### Supported JavaScript objects
The object support can be split into two, basic objects that are stored as-is and containers that support item changes when their types match.

12
diff.js
View File

@ -2347,6 +2347,11 @@ var DiffClassPrototype = {
// proxy generic stuff to .types...
cmp: proxy('types.cmp'),
vars: function(pattern, obj){
var o = {}
this.cmp(pattern, obj, null, o)
return o.ns || {}
},
// XXX do format/version conversion...
fromJSON: function(json){
@ -2529,6 +2534,13 @@ function(diff, obj, options, types){
.patch(obj, options) }
// Extract pattern VAR/LIKE matching values from obj...
//
var vars =
module.vars =
function(pattern, obj){
return Diff.vars(pattern, obj) }
/**********************************************************************