Skip to content

Commit

Permalink
[mutator] Update mutator readme (#406)
Browse files Browse the repository at this point in the history
* [mutator] Update mutator readme

* [mutator] Fix _id placement in readme
  • Loading branch information
Thomas Drevon authored and bjoerge committed Mar 6, 2018
1 parent 3f430ed commit 2ff0084
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/@sanity/mutator/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
## @sanity/mutator

[![Build Status](https://travis-ci.org/sanity-io/mutator.svg?branch=master)](https://travis-ci.org/sanity-io/mutator)

## Features
- Sanity flavored jsonpath matching engine with flexible interface that plays well with React
- An implementation of the mutation operations of Sanity that can be applied to vanilla javascript objects, or through a flexible interface: any weird document representation you may require
- TODO: A model to track documents as they are mutated both locally and remotely through the real time query feature of Sanity

* Sanity flavored jsonpath matching engine with flexible interface that plays
well with React
* An implementation of the mutation operations of Sanity that can be applied to
vanilla javascript objects, or through a flexible interface: any weird
document representation you may require
* TODO: A model to track documents as they are mutated both locally and remotely
through the real time query feature of Sanity
* Note: If `patch.id` doesn't match `document._id`, the patch will be ignored
during `apply`.

## Usage

```javascript
import {Patcher} from '@sanity/mutator'

const document = {
_id: 'a1b2c3',
a: {}
}

const patcher = new Patcher({
id: 'a1b2c3',
set: {
'a.b': 'My new value'
}
Expand All @@ -24,6 +34,7 @@ const patcher = new Patcher({
console.log(patcher.apply(document))

=> {
_id: 'a1b2c3',
a: {
b: 'My new value'
}
Expand Down

0 comments on commit 2ff0084

Please sign in to comment.