]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: document store.patch
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 1 Apr 2021 14:33:09 +0000 (16:33 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 1 Apr 2021 14:33:09 +0000 (16:33 +0200)
docs/core-concepts/state.md

index 858ddfa8e6afe1a04e1b7a08df7a31f9412b36f0..22d3227ce10ec6c1b5001022ed91042731a24dc4 100644 (file)
@@ -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
+})
+```
+
 <!-- TODO: disable this with `strictMode`, `{ noDirectPatch: 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).