]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
feat: make getters optional
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 25 Nov 2019 15:06:05 +0000 (16:06 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 26 Nov 2019 20:00:07 +0000 (21:00 +0100)
__tests__/pinia/stores/cart.ts
__tests__/pinia/stores/combined.ts
__tests__/pinia/stores/user.ts
__tests__/tds/store.test-d.ts
src/index.ts

index cfd206da2162f2672128df2262cf30adb083559b..4a09328e405ffe4250ba6df6d41b79d34d8cb981 100644 (file)
@@ -19,8 +19,7 @@ export const cartStore = makeStore(
 
         return items
       }, [] as { name: string; amount: number }[]),
-  },
-  {}
+  }
 )
 
 export function addItem(name: string) {
index 49e09efcf6cb4c5785c26cedf210cb847f0e1291..939ce7063a93e3ec8ffab7f978a507c826d40585 100644 (file)
@@ -1,2 +1,2 @@
-// in this file we could import other stores that use one each other
-// while avoiding any recursive import
+// in this file we could import other stores that use one each other while
+// avoiding any recursive import
index 7e6b048f4004f691a6428ed70445b85410f24e87..1bd282b50e0041a76e122c7b1a992d5cae56756a 100644 (file)
@@ -6,7 +6,6 @@ export const userStore = makeStore(
     name: 'Eduardo',
     isAdmin: true as boolean,
   }),
-  {},
   {}
 )
 
index a052ac7f329e9688fbfb31321fb869549ad23124..a401b3594c208cd816cb658cf85797be38626189 100644 (file)
@@ -1,16 +1,9 @@
 import { createStore } from '../../src'
 import { expectType, expectError } from 'tsd'
 
-const store = createStore(
-  'name',
-  () => ({ a: 'on' as 'on' | 'off' }),
-  {
-    upper: state => state.a.toUpperCase(),
-  },
-  {
-    doStuff(store, n: number, a: 'on' | 'off') {},
-  }
-)
+const store = createStore('name', () => ({ a: 'on' as 'on' | 'off' }), {
+  upper: state => state.a.toUpperCase(),
+})
 
 expectType<{ a: 'on' | 'off' }>(store.state)
 
index 4d47b42e156b75a74717579c3f2afef22ddca7f7..1bcead4c2b43eafd1a15262aa6b870d3455c0c66 100644 (file)
@@ -154,7 +154,12 @@ export function makeStore<
   Id extends string,
   S extends StateTree,
   G extends Record<string, StoreGetter<S>>
->(id: Id, buildState: () => S, getters: G) {
+>(
+  id: Id,
+  buildState: () => S,
+  // @ts-ignore
+  getters: G = {}
+) {
   let store: CombinedStore<Id, S, G> | undefined
 
   function useStore(): CombinedStore<Id, S, G> {