From 1ed549f1d62c778005ddbb4129d90a56a327663b Mon Sep 17 00:00:00 2001 From: jiyinyiyong Date: Wed, 26 Aug 2015 01:43:17 +0800 Subject: [PATCH] adding an example --- README.md | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 223fc3f..5e0ea6e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,29 @@ -#Immutable Patch +Immutable Patch +==== -Apply RFC 6902 style patches to Immutable.JS data structures, such as `Maps`, `Lists`, and `Sets`. \ No newline at end of file +Apply RFC 6902 style patches to Immutable.JS data structures, such as `Maps`, `Lists`, and `Sets`. + +### Getting Started + +You may get the module via npm: + +``` +npm install immutablepatch +``` + +And apply JSON patches to an immutable JSON object: + +```js +var Immutable = require('immutable'); +var patch = require('immutablepatch'); + +var list = Immutable.fromJS([1, 2, [3, 4]]); +var ops = Immutable.fromJS([ + {op: 'replace', path: '/2/1', value: 10} +]); + +var result = patch(list, ops); +// var expected = Immutable.fromJS([1, 2, [3, 10]]); +``` + +You will probably need [`immutablediff`](https://github.com/intelie/immutable-js-diff) to generate diff operations.