]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
style: format
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 5 Feb 2024 10:12:18 +0000 (11:12 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 5 Feb 2024 10:12:18 +0000 (11:12 +0100)
13 files changed:
.gitignore
.prettierignore
packages/pinia/__tests__/hmr.spec.ts
packages/pinia/__tests__/pinia/stores/cart.ts
packages/pinia/src/devtools/file-saver.ts
packages/pinia/src/devtools/formatting.ts
packages/pinia/src/devtools/plugin.ts
packages/pinia/src/hmr.ts
packages/pinia/src/mapHelpers.ts
packages/pinia/src/rootStore.ts
packages/pinia/src/store.ts
packages/pinia/src/types.ts
packages/playground/src/stores/cart.ts

index c05a9e6ed85a41f6f11fe47e40811941580d1a81..88d6c50c44e4a166fe56a34b00486ada01e25ce4 100644 (file)
@@ -16,3 +16,4 @@ packages/docs/api
 .yalc
 yalc.lock
 .idea
+.vitepress/cache
index 0442789cf772db25c68ff89cfa8263c5dc357ce7..a81df6512aa3815a0490be950a4c1c10ede44742 100644 (file)
@@ -1,3 +1,5 @@
 __build__
 dist
 coverage
+.vitepress/cache
+temp
index 3f84db9c4f01e30e3ac6c97407ae1dbf344434ed..261c0b5246cbf479054515fe7a817ca59fbf924e 100644 (file)
@@ -9,7 +9,7 @@ import {
 } from '../src'
 
 function defineOptions<
-  O extends Omit<DefineStoreOptions<string, StateTree, any, any>, 'id'>
+  O extends Omit<DefineStoreOptions<string, StateTree, any, any>, 'id'>,
 >(options: O): O {
   return options
 }
index b05042681fe5c4a399f574dc1a1a0a68d265224e..045044d41949903c8a3bdbf40486661e032e322b 100644 (file)
@@ -8,17 +8,20 @@ export const useCartStore = defineStore('cart', {
   }),
   getters: {
     items: (state) =>
-      state.rawItems.reduce((items, item) => {
-        const existingItem = items.find((it) => it.name === item)
+      state.rawItems.reduce(
+        (items, item) => {
+          const existingItem = items.find((it) => it.name === item)
 
-        if (!existingItem) {
-          items.push({ name: item, amount: 1 })
-        } else {
-          existingItem.amount++
-        }
+          if (!existingItem) {
+            items.push({ name: item, amount: 1 })
+          } else {
+            existingItem.amount++
+          }
 
-        return items
-      }, [] as { name: string; amount: number }[]),
+          return items
+        },
+        [] as { name: string; amount: number }[]
+      ),
   },
 
   actions: {
index 292326727330fc2584098d643d9ac25f28231458..69a8ed5bfdc630990907e3ab8184ad2788b4bfa2 100644 (file)
@@ -15,12 +15,12 @@ const _global = /*#__PURE__*/ (() =>
   typeof window === 'object' && window.window === window
     ? window
     : typeof self === 'object' && self.self === self
-    ? self
-    : typeof global === 'object' && global.global === global
-    ? global
-    : typeof globalThis === 'object'
-    ? globalThis
-    : { HTMLElement: null })()
+      ? self
+      : typeof global === 'object' && global.global === global
+        ? global
+        : typeof globalThis === 'object'
+          ? globalThis
+          : { HTMLElement: null })()
 
 export interface Options {
   autoBom?: boolean
@@ -112,15 +112,15 @@ export type SaveAs =
 export const saveAs: SaveAs = !IS_CLIENT
   ? () => {} // noop
   : // Use download attribute first if possible (#193 Lumia mobile) unless this is a macOS WebView or mini program
-  typeof HTMLAnchorElement !== 'undefined' &&
-    'download' in HTMLAnchorElement.prototype &&
-    !isMacOSWebView
-  ? downloadSaveAs
-  : // Use msSaveOrOpenBlob as a second approach
-  'msSaveOrOpenBlob' in _navigator
-  ? msSaveAs
-  : // Fallback to using FileReader and a popup
-    fileSaverSaveAs
+    typeof HTMLAnchorElement !== 'undefined' &&
+      'download' in HTMLAnchorElement.prototype &&
+      !isMacOSWebView
+    ? downloadSaveAs
+    : // Use msSaveOrOpenBlob as a second approach
+      'msSaveOrOpenBlob' in _navigator
+      ? msSaveAs
+      : // Fallback to using FileReader and a popup
+        fileSaverSaveAs
 
 function downloadSaveAs(blob: Blob, name: string = 'download', opts?: Options) {
   const a = document.createElement('a')
index 0f2eeb8efb0164d7c9f2fdaca12198cdb69c88cc..651c9ef3c66cc348dc6d5fdd2b413adc658485c3 100644 (file)
@@ -53,10 +53,13 @@ export function formatStoreForInspectorState(
           return {
             editable: false,
             key: id,
-            value: store._getters!.reduce((getters, key) => {
-              getters[key] = store[key]
-              return getters
-            }, {} as Record<string, any>),
+            value: store._getters!.reduce(
+              (getters, key) => {
+                getters[key] = store[key]
+                return getters
+              },
+              {} as Record<string, any>
+            ),
           }
         }),
     }
index 646b395673675751697ab6fea18dedbcf2889765..82d36bd8c23415caa60ba07b172dc99a9271ceba 100644 (file)
@@ -556,7 +556,7 @@ export function devtoolsPlugin<
   Id extends string = string,
   S extends StateTree = StateTree,
   G extends object = _GettersTree<S>,
-  A extends object = _ActionsTree
+  A extends object = _ActionsTree,
 >({ app, store, options }: PiniaPluginContext<Id, S, G, A>) {
   // HMR module
   if (store.$id.startsWith('__hot:')) {
index 5424b1785b05d09188ae2632b07296654b26a8f0..b5798d49e9450ec8789649c9ac8c267dd8b5cc9a 100644 (file)
@@ -82,7 +82,7 @@ export function acceptHMRUpdate<
   Id extends string = string,
   S extends StateTree = StateTree,
   G extends _GettersTree<S> = _GettersTree<S>,
-  A = _ActionsTree
+  A = _ActionsTree,
 >(initialUseStore: StoreDefinition<Id, S, G, A>, hot: any) {
   // strip as much as possible from iife.prod
   if (!__DEV__) {
index 33803a0080fe3f5c0d18bb3c3e541d24aa4dec2b..c33d8fbffbb5623ad8c63addf20716903ff48d07 100644 (file)
@@ -22,33 +22,34 @@ export interface MapStoresCustomization {
 /**
  * For internal use **only**.
  */
-export type _StoreObject<S> = S extends StoreDefinition<
-  infer Ids,
-  infer State,
-  infer Getters,
-  infer Actions
->
-  ? {
-      [Id in `${Ids}${MapStoresCustomization extends Record<
-        'suffix',
-        infer Suffix
-      >
-        ? Suffix
-        : 'Store'}`]: () => Store<
-        Id extends `${infer RealId}${MapStoresCustomization extends Record<
+export type _StoreObject<S> =
+  S extends StoreDefinition<
+    infer Ids,
+    infer State,
+    infer Getters,
+    infer Actions
+  >
+    ? {
+        [Id in `${Ids}${MapStoresCustomization extends Record<
           'suffix',
           infer Suffix
         >
           ? Suffix
-          : 'Store'}`
-          ? RealId
-          : string,
-        State,
-        Getters,
-        Actions
-      >
-    }
-  : {}
+          : 'Store'}`]: () => Store<
+          Id extends `${infer RealId}${MapStoresCustomization extends Record<
+            'suffix',
+            infer Suffix
+          >
+            ? Suffix
+            : 'Store'}`
+            ? RealId
+            : string,
+          State,
+          Getters,
+          Actions
+        >
+      }
+    : {}
 
 /**
  * For internal use **only**.
@@ -128,7 +129,7 @@ export function mapStores<Stores extends any[]>(
 export type _MapStateReturn<
   S extends StateTree,
   G extends _GettersTree<S>,
-  Keys extends keyof S | keyof G = keyof S | keyof G
+  Keys extends keyof S | keyof G = keyof S | keyof G,
 > = {
   // [key in keyof S | keyof G]: () => key extends keyof S
   //   ? S[key]
@@ -149,13 +150,13 @@ export type _MapStateObjectReturn<
   T extends Record<
     string,
     keyof S | keyof G | ((store: Store<Id, S, G, A>) => any)
-  > = {}
+  > = {},
 > = {
   [key in keyof T]: () => T[key] extends (store: any) => infer R
     ? R
     : T[key] extends keyof Store<Id, S, G, A>
-    ? Store<Id, S, G, A>[T[key]]
-    : never
+      ? Store<Id, S, G, A>[T[key]]
+      : never
 }
 
 /**
@@ -202,7 +203,7 @@ export function mapState<
   KeyMapper extends Record<
     string,
     keyof S | keyof G | ((store: Store<Id, S, G, A>) => any)
-  >
+  >,
 >(
   useStore: StoreDefinition<Id, S, G, A>,
   keyMapper: KeyMapper
@@ -236,7 +237,7 @@ export function mapState<
   S extends StateTree,
   G extends _GettersTree<S>,
   A,
-  Keys extends keyof S | keyof G
+  Keys extends keyof S | keyof G,
 >(
   useStore: StoreDefinition<Id, S, G, A>,
   keys: readonly Keys[]
@@ -254,31 +255,40 @@ export function mapState<
   Id extends string,
   S extends StateTree,
   G extends _GettersTree<S>,
-  A
+  A,
 >(
   useStore: StoreDefinition<Id, S, G, A>,
   keysOrMapper: any
 ): _MapStateReturn<S, G> | _MapStateObjectReturn<Id, S, G, A> {
   return Array.isArray(keysOrMapper)
-    ? keysOrMapper.reduce((reduced, key) => {
-        reduced[key] = function (this: ComponentPublicInstance) {
-          return useStore(this.$pinia)[key]
-        } as () => any
-        return reduced
-      }, {} as _MapStateReturn<S, G>)
-    : Object.keys(keysOrMapper).reduce((reduced, key: string) => {
-        // @ts-expect-error
-        reduced[key] = function (this: ComponentPublicInstance) {
-          const store = useStore(this.$pinia)
-          const storeKey = keysOrMapper[key]
-          // for some reason TS is unable to infer the type of storeKey to be a
-          // function
-          return typeof storeKey === 'function'
-            ? (storeKey as (store: Store<Id, S, G, A>) => any).call(this, store)
-            : store[storeKey]
-        }
-        return reduced
-      }, {} as _MapStateObjectReturn<Id, S, G, A>)
+    ? keysOrMapper.reduce(
+        (reduced, key) => {
+          reduced[key] = function (this: ComponentPublicInstance) {
+            return useStore(this.$pinia)[key]
+          } as () => any
+          return reduced
+        },
+        {} as _MapStateReturn<S, G>
+      )
+    : Object.keys(keysOrMapper).reduce(
+        (reduced, key: string) => {
+          // @ts-expect-error
+          reduced[key] = function (this: ComponentPublicInstance) {
+            const store = useStore(this.$pinia)
+            const storeKey = keysOrMapper[key]
+            // for some reason TS is unable to infer the type of storeKey to be a
+            // function
+            return typeof storeKey === 'function'
+              ? (storeKey as (store: Store<Id, S, G, A>) => any).call(
+                  this,
+                  store
+                )
+              : store[storeKey]
+          }
+          return reduced
+        },
+        {} as _MapStateObjectReturn<Id, S, G, A>
+      )
 }
 
 /**
@@ -331,7 +341,7 @@ export function mapActions<
   S extends StateTree,
   G extends _GettersTree<S>,
   A,
-  KeyMapper extends Record<string, keyof A>
+  KeyMapper extends Record<string, keyof A>,
 >(
   useStore: StoreDefinition<Id, S, G, A>,
   keyMapper: KeyMapper
@@ -363,7 +373,7 @@ export function mapActions<
   Id extends string,
   S extends StateTree,
   G extends _GettersTree<S>,
-  A
+  A,
 >(
   useStore: StoreDefinition<Id, S, G, A>,
   keys: Array<keyof A>
@@ -381,7 +391,7 @@ export function mapActions<
   S extends StateTree,
   G extends _GettersTree<S>,
   A,
-  KeyMapper extends Record<string, keyof A>
+  KeyMapper extends Record<string, keyof A>,
 >(
   useStore: StoreDefinition<Id, S, G, A>,
   keysOrMapper: Array<keyof A> | KeyMapper
@@ -397,16 +407,19 @@ export function mapActions<
         }
         return reduced
       }, {} as _MapActionsReturn<A>)
-    : Object.keys(keysOrMapper).reduce((reduced, key: keyof KeyMapper) => {
-        // @ts-expect-error
-        reduced[key] = function (
-          this: ComponentPublicInstance,
-          ...args: any[]
-        ) {
-          return useStore(this.$pinia)[keysOrMapper[key]](...args)
-        }
-        return reduced
-      }, {} as _MapActionsObjectReturn<A, KeyMapper>)
+    : Object.keys(keysOrMapper).reduce(
+        (reduced, key: keyof KeyMapper) => {
+          // @ts-expect-error
+          reduced[key] = function (
+            this: ComponentPublicInstance,
+            ...args: any[]
+          ) {
+            return useStore(this.$pinia)[keysOrMapper[key]](...args)
+          }
+          return reduced
+        },
+        {} as _MapActionsObjectReturn<A, KeyMapper>
+      )
 }
 
 /**
@@ -424,7 +437,7 @@ export type _MapWritableStateReturn<S extends StateTree> = {
  */
 export type _MapWritableStateObjectReturn<
   S extends StateTree,
-  T extends Record<string, keyof S>
+  T extends Record<string, keyof S>,
 > = {
   [key in keyof T]: {
     get: () => S[T[key]]
@@ -445,7 +458,7 @@ export function mapWritableState<
   S extends StateTree,
   G extends _GettersTree<S>,
   A,
-  KeyMapper extends Record<string, keyof S>
+  KeyMapper extends Record<string, keyof S>,
 >(
   useStore: StoreDefinition<Id, S, G, A>,
   keyMapper: KeyMapper
@@ -463,7 +476,7 @@ export function mapWritableState<
   S extends StateTree,
   G extends _GettersTree<S>,
   A,
-  Keys extends keyof S
+  Keys extends keyof S,
 >(
   useStore: StoreDefinition<Id, S, G, A>,
   keys: readonly Keys[]
@@ -486,7 +499,7 @@ export function mapWritableState<
   S extends StateTree,
   G extends _GettersTree<S>,
   A,
-  KeyMapper extends Record<string, keyof S>
+  KeyMapper extends Record<string, keyof S>,
 >(
   useStore: StoreDefinition<Id, S, G, A>,
   keysOrMapper: Array<keyof S> | KeyMapper
@@ -505,17 +518,20 @@ export function mapWritableState<
         }
         return reduced
       }, {} as _MapWritableStateReturn<S>)
-    : Object.keys(keysOrMapper).reduce((reduced, key: keyof KeyMapper) => {
-        // @ts-ignore
-        reduced[key] = {
-          get(this: ComponentPublicInstance) {
-            return useStore(this.$pinia)[keysOrMapper[key]]
-          },
-          set(this: ComponentPublicInstance, value) {
-            // it's easier to type it here as any
-            return (useStore(this.$pinia)[keysOrMapper[key]] = value as any)
-          },
-        }
-        return reduced
-      }, {} as _MapWritableStateObjectReturn<S, KeyMapper>)
+    : Object.keys(keysOrMapper).reduce(
+        (reduced, key: keyof KeyMapper) => {
+          // @ts-ignore
+          reduced[key] = {
+            get(this: ComponentPublicInstance) {
+              return useStore(this.$pinia)[keysOrMapper[key]]
+            },
+            set(this: ComponentPublicInstance, value) {
+              // it's easier to type it here as any
+              return (useStore(this.$pinia)[keysOrMapper[key]] = value as any)
+            },
+          }
+          return reduced
+        },
+        {} as _MapWritableStateObjectReturn<S, KeyMapper>
+      )
 }
index 1ee39576525256110b17b59fbe9021f836d76112..1b30996a5f58784725fc855ffa8e991c5691bf1f 100644 (file)
@@ -110,7 +110,7 @@ export interface PiniaPluginContext<
   Id extends string = string,
   S extends StateTree = StateTree,
   G /* extends _GettersTree<S> */ = _GettersTree<S>,
-  A /* extends _ActionsTree */ = _ActionsTree
+  A /* extends _ActionsTree */ = _ActionsTree,
 > {
   /**
    * pinia instance.
@@ -143,9 +143,9 @@ export interface PiniaPlugin {
    *
    * @param context - Context
    */
-  (context: PiniaPluginContext): Partial<
-    PiniaCustomProperties & PiniaCustomStateProperties
-  > | void
+  (
+    context: PiniaPluginContext
+  ): Partial<PiniaCustomProperties & PiniaCustomStateProperties> | void
 }
 
 /**
index e781da0d8a757df29fe15914186fc1e389c0bfe8..68e67f55f190f1a1f6079d3747e8eff5637707f6 100644 (file)
@@ -57,7 +57,7 @@ const fallbackRunWithContext = (fn: () => unknown) => fn()
 type _ArrayType<AT> = AT extends Array<infer T> ? T : never
 
 function mergeReactiveObjects<
-  T extends Record<any, unknown> | Map<unknown, unknown> | Set<unknown>
+  T extends Record<any, unknown> | Map<unknown, unknown> | Set<unknown>,
 >(target: T, patchToApply: _DeepPartial<T>): T {
   // Handle Map instances
   if (target instanceof Map && patchToApply instanceof Map) {
@@ -135,7 +135,7 @@ function createOptionsStore<
   Id extends string,
   S extends StateTree,
   G extends _GettersTree<S>,
-  A extends _ActionsTree
+  A extends _ActionsTree,
 >(
   id: Id,
   options: DefineStoreOptions<Id, S, G, A>,
@@ -168,31 +168,34 @@ function createOptionsStore<
     return assign(
       localState,
       actions,
-      Object.keys(getters || {}).reduce((computedGetters, name) => {
-        if (__DEV__ && name in localState) {
-          console.warn(
-            `[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "${name}" in store "${id}".`
-          )
-        }
+      Object.keys(getters || {}).reduce(
+        (computedGetters, name) => {
+          if (__DEV__ && name in localState) {
+            console.warn(
+              `[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "${name}" in store "${id}".`
+            )
+          }
 
-        computedGetters[name] = markRaw(
-          computed(() => {
-            setActivePinia(pinia)
-            // it was created just before
-            const store = pinia._s.get(id)!
+          computedGetters[name] = markRaw(
+            computed(() => {
+              setActivePinia(pinia)
+              // it was created just before
+              const store = pinia._s.get(id)!
 
-            // allow cross using stores
-            /* istanbul ignore if */
-            if (isVue2 && !store._r) return
+              // allow cross using stores
+              /* istanbul ignore if */
+              if (isVue2 && !store._r) return
 
-            // @ts-expect-error
-            // return getters![name].call(context, context)
-            // TODO: avoid reading the getter while assigning with a global variable
-            return getters![name].call(store, store)
-          })
-        )
-        return computedGetters
-      }, {} as Record<string, ComputedRef>)
+              // @ts-expect-error
+              // return getters![name].call(context, context)
+              // TODO: avoid reading the getter while assigning with a global variable
+              return getters![name].call(store, store)
+            })
+          )
+          return computedGetters
+        },
+        {} as Record<string, ComputedRef>
+      )
     )
   }
 
@@ -206,7 +209,7 @@ function createSetupStore<
   SS extends Record<any, unknown>,
   S extends StateTree,
   G extends Record<string, _Method>,
-  A extends _ActionsTree
+  A extends _ActionsTree,
 >(
   $id: Id,
   setup: () => SS,
@@ -334,13 +337,13 @@ function createSetupStore<
         })
       }
     : /* istanbul ignore next */
-    __DEV__
-    ? () => {
-        throw new Error(
-          `🍍: Store "${$id}" is built using the setup syntax and does not implement $reset().`
-        )
-      }
-    : noop
+      __DEV__
+      ? () => {
+          throw new Error(
+            `🍍: Store "${$id}" is built using the setup syntax and does not implement $reset().`
+          )
+        }
+      : noop
 
   function $dispose() {
     scope.stop()
@@ -760,40 +763,28 @@ function createSetupStore<
  * Extract the actions of a store type. Works with both a Setup Store or an
  * Options Store.
  */
-export type StoreActions<SS> = SS extends Store<
-  string,
-  StateTree,
-  _GettersTree<StateTree>,
-  infer A
->
-  ? A
-  : _ExtractActionsFromSetupStore<SS>
+export type StoreActions<SS> =
+  SS extends Store<string, StateTree, _GettersTree<StateTree>, infer A>
+    ? A
+    : _ExtractActionsFromSetupStore<SS>
 
 /**
  * Extract the getters of a store type. Works with both a Setup Store or an
  * Options Store.
  */
-export type StoreGetters<SS> = SS extends Store<
-  string,
-  StateTree,
-  infer G,
-  _ActionsTree
->
-  ? _StoreWithGetters<G>
-  : _ExtractGettersFromSetupStore<SS>
+export type StoreGetters<SS> =
+  SS extends Store<string, StateTree, infer G, _ActionsTree>
+    ? _StoreWithGetters<G>
+    : _ExtractGettersFromSetupStore<SS>
 
 /**
  * Extract the state of a store type. Works with both a Setup Store or an
  * Options Store. Note this unwraps refs.
  */
-export type StoreState<SS> = SS extends Store<
-  string,
-  infer S,
-  _GettersTree<StateTree>,
-  _ActionsTree
->
-  ? UnwrapRef<S>
-  : _ExtractStateFromSetupStore<SS>
+export type StoreState<SS> =
+  SS extends Store<string, infer S, _GettersTree<StateTree>, _ActionsTree>
+    ? UnwrapRef<S>
+    : _ExtractStateFromSetupStore<SS>
 
 // type a1 = _ExtractStateFromSetupStore<{ a: Ref<number>; action: () => void }>
 // type a2 = _ExtractActionsFromSetupStore<{ a: Ref<number>; action: () => void }>
@@ -814,7 +805,7 @@ export function defineStore<
   S extends StateTree = {},
   G extends _GettersTree<S> = {},
   // cannot extends ActionsTree because we loose the typings
-  A /* extends ActionsTree */ = {}
+  A /* extends ActionsTree */ = {},
 >(
   id: Id,
   options: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>
@@ -830,7 +821,7 @@ export function defineStore<
   S extends StateTree = {},
   G extends _GettersTree<S> = {},
   // cannot extends ActionsTree because we loose the typings
-  A /* extends ActionsTree */ = {}
+  A /* extends ActionsTree */ = {},
 >(options: DefineStoreOptions<Id, S, G, A>): StoreDefinition<Id, S, G, A>
 
 /**
index 3eb11800f8dd47fd1cf833db9a7d8d0dab8642d1..0c3359cd74a708cdb42e8e2133311299d11b94de 100644 (file)
@@ -162,10 +162,10 @@ export type SubscriptionCallback<S> = (
 export type _Awaited<T> = T extends null | undefined
   ? T // special case for `null | undefined` when not in `--strictNullChecks` mode
   : T extends object & { then(onfulfilled: infer F): any } // `await` only unwraps object types with a callable `then`. Non-object types are not unwrapped
-  ? F extends (value: infer V, ...args: any) => any // if the argument to `then` is callable, extracts the first argument
-    ? _Awaited<V> // recursively unwrap the value
-    : never // the argument to `then` was not callable
-  : T // non-object or non-thenable
+    ? F extends (value: infer V, ...args: any) => any // if the argument to `then` is callable, extracts the first argument
+      ? _Awaited<V> // recursively unwrap the value
+      : never // the argument to `then` was not callable
+    : T // non-object or non-thenable
 
 /**
  * Actual type for {@link StoreOnActionListenerContext}. Exists for refactoring
@@ -175,7 +175,7 @@ export type _Awaited<T> = T extends null | undefined
 export interface _StoreOnActionListenerContext<
   Store,
   ActionName extends string,
-  A
+  A,
 > {
   /**
    * Name of the action
@@ -219,7 +219,7 @@ export type StoreOnActionListenerContext<
   Id extends string,
   S extends StateTree,
   G /* extends GettersTree<S> */,
-  A /* extends ActionsTree */
+  A /* extends ActionsTree */,
 > = _ActionsTree extends A
   ? _StoreOnActionListenerContext<StoreGeneric, string, _ActionsTree>
   : {
@@ -235,7 +235,7 @@ export type StoreOnActionListener<
   Id extends string,
   S extends StateTree,
   G /* extends GettersTree<S> */,
-  A /* extends ActionsTree */
+  A /* extends ActionsTree */,
 > = (
   context: StoreOnActionListenerContext<
     Id,
@@ -318,7 +318,7 @@ export interface _StoreWithState<
   Id extends string,
   S extends StateTree,
   G /* extends GettersTree<StateTree> */,
-  A /* extends ActionsTree */
+  A /* extends ActionsTree */,
 > extends StoreProperties<Id> {
   /**
    * State of the Store. Setting it will internally call `$patch()` to update the state.
@@ -465,7 +465,7 @@ export type Store<
   S extends StateTree = {},
   G /* extends GettersTree<S>*/ = {},
   // has the actions without the context (this) for typings
-  A /* extends ActionsTree */ = {}
+  A /* extends ActionsTree */ = {},
 > = _StoreWithState<Id, S, G, A> &
   UnwrapRef<S> &
   _StoreWithGetters<G> &
@@ -493,7 +493,7 @@ export interface StoreDefinition<
   Id extends string = string,
   S extends StateTree = StateTree,
   G /* extends GettersTree<S>*/ = _GettersTree<S>,
-  A /* extends ActionsTree */ = _ActionsTree
+  A /* extends ActionsTree */ = _ActionsTree,
 > {
   /**
    * Returns a store, creates it if necessary.
@@ -523,7 +523,7 @@ export interface PiniaCustomProperties<
   Id extends string = string,
   S extends StateTree = StateTree,
   G /* extends GettersTree<S> */ = _GettersTree<S>,
-  A /* extends ActionsTree */ = _ActionsTree
+  A /* extends ActionsTree */ = _ActionsTree,
 > {}
 
 /**
@@ -583,8 +583,8 @@ export type _UnwrapAll<SS> = { [K in keyof SS]: UnwrapRef<SS[K]> }
 export type _ExtractStateFromSetupStore<SS> = SS extends undefined | void
   ? {}
   : _ExtractStateFromSetupStore_Keys<SS> extends keyof SS
-  ? _UnwrapAll<Pick<SS, _ExtractStateFromSetupStore_Keys<SS>>>
-  : never
+    ? _UnwrapAll<Pick<SS, _ExtractStateFromSetupStore_Keys<SS>>>
+    : never
 
 /**
  * For internal use **only**
@@ -592,8 +592,8 @@ export type _ExtractStateFromSetupStore<SS> = SS extends undefined | void
 export type _ExtractActionsFromSetupStore<SS> = SS extends undefined | void
   ? {}
   : _ExtractActionsFromSetupStore_Keys<SS> extends keyof SS
-  ? Pick<SS, _ExtractActionsFromSetupStore_Keys<SS>>
-  : never
+    ? Pick<SS, _ExtractActionsFromSetupStore_Keys<SS>>
+    : never
 
 /**
  * For internal use **only**
@@ -601,8 +601,8 @@ export type _ExtractActionsFromSetupStore<SS> = SS extends undefined | void
 export type _ExtractGettersFromSetupStore<SS> = SS extends undefined | void
   ? {}
   : _ExtractGettersFromSetupStore_Keys<SS> extends keyof SS
-  ? Pick<SS, _ExtractGettersFromSetupStore_Keys<SS>>
-  : never
+    ? Pick<SS, _ExtractGettersFromSetupStore_Keys<SS>>
+    : never
 
 /**
  * Options passed to `defineStore()` that are common between option and setup
@@ -619,7 +619,7 @@ export interface DefineStoreOptions<
   Id extends string,
   S extends StateTree,
   G /* extends GettersTree<S> */,
-  A /* extends Record<string, StoreAction> */
+  A /* extends Record<string, StoreAction> */,
 > extends DefineStoreOptionsBase<S, Store<Id, S, G, A>> {
   /**
    * Unique string key to identify the store across the application.
@@ -687,7 +687,7 @@ export interface DefineSetupStoreOptions<
   // NOTE: Passing SS seems to make TS crash
   S extends StateTree,
   G,
-  A /* extends ActionsTree */
+  A /* extends ActionsTree */,
 > extends DefineStoreOptionsBase<S, Store<Id, S, G, A>> {
   /**
    * Extracted actions. Added by useStore(). SHOULD NOT be added by the user when
@@ -704,7 +704,7 @@ export interface DefineStoreOptionsInPlugin<
   Id extends string,
   S extends StateTree,
   G,
-  A
+  A,
 > extends Omit<DefineStoreOptions<Id, S, G, A>, 'id' | 'actions'> {
   /**
    * Extracted object of actions. Added by useStore() when the store is built
index 1adeaba7ed401e32bafbaffeece7866f0f115db6..210b60562d75871a607db42c55dadd0e45e4328d 100644 (file)
@@ -8,17 +8,20 @@ export const useCartStore = defineStore({
   }),
   getters: {
     items: (state) =>
-      state.rawItems.reduce((items, item) => {
-        const existingItem = items.find((it) => it.name === item)
+      state.rawItems.reduce(
+        (items, item) => {
+          const existingItem = items.find((it) => it.name === item)
 
-        if (!existingItem) {
-          items.push({ name: item, amount: 1 })
-        } else {
-          existingItem.amount++
-        }
+          if (!existingItem) {
+            items.push({ name: item, amount: 1 })
+          } else {
+            existingItem.amount++
+          }
 
-        return items
-      }, [] as Array<{ name: string; amount: number }>),
+          return items
+        },
+        [] as Array<{ name: string; amount: number }>
+      ),
   },
   actions: {
     addItem(name: string) {