From 2ff0084a1eb17f40ec57aa54b5046410887a501d Mon Sep 17 00:00:00 2001 From: Thomas Drevon Date: Tue, 6 Mar 2018 21:50:45 +0100 Subject: [PATCH] [mutator] Update mutator readme (#406) * [mutator] Update mutator readme * [mutator] Fix _id placement in readme --- packages/@sanity/mutator/README.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/@sanity/mutator/README.md b/packages/@sanity/mutator/README.md index 3a30ec4a184..5ac42969b26 100644 --- a/packages/@sanity/mutator/README.md +++ b/packages/@sanity/mutator/README.md @@ -1,10 +1,18 @@ ## @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 @@ -12,10 +20,12 @@ import {Patcher} from '@sanity/mutator' const document = { + _id: 'a1b2c3', a: {} } const patcher = new Patcher({ + id: 'a1b2c3', set: { 'a.b': 'My new value' } @@ -24,6 +34,7 @@ const patcher = new Patcher({ console.log(patcher.apply(document)) => { + _id: 'a1b2c3', a: { b: 'My new value' }