]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
feat(devtools): allow resetting fromp pinia inspector
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 25 Jul 2022 09:34:13 +0000 (11:34 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 25 Jul 2022 09:34:13 +0000 (11:34 +0200)
packages/pinia/src/devtools/plugin.ts

index 97b08c463cb95fe1adf7c4400b0a4863c127624b..d62ac5f0d85faf63912bfacd9396f07db8dd7215 100644 (file)
@@ -114,6 +114,29 @@ export function registerPiniaDevtools(app: DevtoolsApp, pinia: Pinia) {
             tooltip: 'Import the state from a JSON file',
           },
         ],
+        nodeActions: [
+          {
+            icon: 'restore',
+            tooltip: 'Reset the state (option store only)',
+            action: (nodeId) => {
+              const store = pinia._s.get(nodeId)
+              if (!store) {
+                toastMessage(
+                  `Cannot reset "${nodeId}" store because it wasn't found.`,
+                  'warn'
+                )
+              } else if (!store._isOptionsAPI) {
+                toastMessage(
+                  `Cannot reset "${nodeId}" store because it's a setup store.`,
+                  'warn'
+                )
+              } else {
+                store.$reset()
+                toastMessage(`Store "${nodeId}" reset.`)
+              }
+            },
+          },
+        ],
       })
 
       api.on.inspectComponent((payload, ctx) => {