From f73fa02ed0084ee562a2d82884bc0b698274f1dd Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 1 Apr 2021 16:33:09 +0200 Subject: [PATCH] docs: document store.patch --- docs/core-concepts/state.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/core-concepts/state.md b/docs/core-concepts/state.md index 858ddfa8..22d3227c 100644 --- a/docs/core-concepts/state.md +++ b/docs/core-concepts/state.md @@ -40,6 +40,15 @@ store.$patch({ }) ``` +The `$path` method also accepts a function to group object mutations that are difficult to apply with an object, e.g. array mutations: + +```js +cartStore.$patch((state) => { + state.items.push({ name: 'shoes', quantity: 1 }) + state.hasChanged = true +}) +``` + The main difference here is that `$patch()` allows you to group multiple changes into one single entry in the devtools. Note **both, direct changes to `state` and `$patch()` appear in the devtools** and can be time travelled (not yet in Vue 3). -- 2.47.3