mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-28 10:30:09 +00:00
added filtering to docs + some twaks...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
1edeb867fa
commit
1b0e03cf44
26
README.md
26
README.md
@ -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
13
diff.js
@ -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???
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user