From: Eduardo San Martin Morote Date: Thu, 1 Apr 2021 14:33:09 +0000 (+0200) Subject: docs: document store.patch X-Git-Tag: v2.0.0-alpha.10~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f73fa02ed0084ee562a2d82884bc0b698274f1dd;p=thirdparty%2Fvuejs%2Fpinia.git docs: document store.patch --- 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).