1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/addon-sdk/source/lib/diffpatcher/Readme.md Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,70 @@ 1.4 +# diffpatcher 1.5 + 1.6 +[](http://travis-ci.org/Gozala/diffpatcher) 1.7 + 1.8 +[](http://ci.testling.com/Gozala/diffpatcher) 1.9 + 1.10 +Diffpatcher is a small library that lets you treat hashes as if they were 1.11 +git repositories. 1.12 + 1.13 +## diff 1.14 + 1.15 +Diff function that takes two hashes and returns delta hash. 1.16 + 1.17 +```js 1.18 +var diff = require("diffpatcher/diff") 1.19 + 1.20 +diff({ a: { b: 1 }, c: { d: 2 } }, // hash#1 1.21 + { a: { e: 3 }, c: { d: 4 } }) // hash#2 1.22 + 1.23 +// => { // delta 1.24 +// a: { 1.25 +// b: null, // - 1.26 +// e: 3 // + 1.27 +// }, 1.28 +// c: { 1.29 +// d: 4 // ± 1.30 +// } 1.31 +// } 1.32 +``` 1.33 + 1.34 +As you can see from the example above `delta` makes no real distinction between 1.35 +proprety upadate and property addition. Try to think of additions as an update 1.36 +from `undefined` to whatever it's being updated to. 1.37 + 1.38 +## patch 1.39 + 1.40 +Patch fuction takes a `hash` and a `delta` and returns a new `hash` which is 1.41 +just like orginial but with delta applied to it. Let's apply delta from the 1.42 +previous example to the first hash from the same example 1.43 + 1.44 + 1.45 +```js 1.46 +var patch = require("diffpatcher/patch") 1.47 + 1.48 +patch({ a: { b: 1 }, c: { d: 2 } }, // hash#1 1.49 + { // delta 1.50 + a: { 1.51 + b: null, // - 1.52 + e: 3 // + 1.53 + }, 1.54 + c: { 1.55 + d: 4 // ± 1.56 + } 1.57 + }) 1.58 + 1.59 +// => { a: { e: 3 }, c: { d: 4 } } // hash#2 1.60 +``` 1.61 + 1.62 +That's about it really, just diffing hashes and applying thes diffs on them. 1.63 + 1.64 + 1.65 +### rebase 1.66 + 1.67 +And as Linus mentioned everything in git can be expressed with `rebase`, that 1.68 +also pretty much the case for `diffpatcher`. `rebase` takes `target` hash, 1.69 +and rebases `parent` onto it with `diff` applied. 1.70 + 1.71 +## Install 1.72 + 1.73 + npm install diffpatcher