diff --git a/README.md b/README.md index 4088a0c..2a9fc0c 100644 --- a/README.md +++ b/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 diff --git a/diff.js b/diff.js index d2b53b2..224ffd8 100644 --- a/diff.js +++ b/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???