added filtering to docs + some twaks...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-08-25 20:06:33 +03:00
parent 1edeb867fa
commit 1b0e03cf44
2 changed files with 32 additions and 7 deletions

View File

@ -145,8 +145,30 @@ Since we applied all the changes to `Bill2`, now he looks just like `Ted`:
### Partial patching
XXX partial patch...
XXX modify the diff -- teach Ted guitar...
Lets just *patch* `Bill`'s the skill level...
```javascript
diff
// only keep the changes to skills...
.filter('skills/*')
.patch(Bill)
```
Now, `Bill` can also play guitar!
```json
{
"name": "Bill",
"age": 20,
"hair": "black",
"skills": [
"awsome",
"time travel",
"guitar"
]
}
```
### Checking

13
diff.js
View File

@ -2122,7 +2122,11 @@ var DiffPrototype = {
unpatch: function(obj){
return this.reverse().patch(obj) },
// XXX add support for '**' path globs...
//
// .filter(path)
// .filter(func)
// -> diff
//
filter: function(filter){
var res = this.clone()
@ -2140,7 +2144,7 @@ var DiffPrototype = {
// ...
// ]
// XXX when OF(..) is ready, replace '**' with OF(ANY, ANY)...
var path = (filter instanceof Array ? filter : [filter])
var pattern = (filter instanceof Array ? filter : [filter])
// '*' -> ANY
.map(function(e){
return e == '*' ? ANY : e })
@ -2159,7 +2163,7 @@ var DiffPrototype = {
}, [])
// min length...
var min = path
var min = pattern
.reduce(function(l, e){
return l + (e instanceof Array ? e.length : 0) }, 0)
@ -2191,8 +2195,7 @@ var DiffPrototype = {
// XXX Q: should we ignore the last element of the path???
filter = function(change, i, lst){
//return cmp(path, change.path) }
return test(change.path) }
return test(change.path, pattern) }
}
// XXX should we add filter to options or at least set a .filtered attr???