From: Eduardo San Martin Morote Date: Mon, 25 Nov 2019 15:06:05 +0000 (+0100) Subject: feat: make getters optional X-Git-Tag: v0.0.1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18b5756b97d4551acc18667468be60e524159bbf;p=thirdparty%2Fvuejs%2Fpinia.git feat: make getters optional --- diff --git a/__tests__/pinia/stores/cart.ts b/__tests__/pinia/stores/cart.ts index cfd206da..4a09328e 100644 --- a/__tests__/pinia/stores/cart.ts +++ b/__tests__/pinia/stores/cart.ts @@ -19,8 +19,7 @@ export const cartStore = makeStore( return items }, [] as { name: string; amount: number }[]), - }, - {} + } ) export function addItem(name: string) { diff --git a/__tests__/pinia/stores/combined.ts b/__tests__/pinia/stores/combined.ts index 49e09efc..939ce706 100644 --- a/__tests__/pinia/stores/combined.ts +++ b/__tests__/pinia/stores/combined.ts @@ -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 diff --git a/__tests__/pinia/stores/user.ts b/__tests__/pinia/stores/user.ts index 7e6b048f..1bd282b5 100644 --- a/__tests__/pinia/stores/user.ts +++ b/__tests__/pinia/stores/user.ts @@ -6,7 +6,6 @@ export const userStore = makeStore( name: 'Eduardo', isAdmin: true as boolean, }), - {}, {} ) diff --git a/__tests__/tds/store.test-d.ts b/__tests__/tds/store.test-d.ts index a052ac7f..a401b359 100644 --- a/__tests__/tds/store.test-d.ts +++ b/__tests__/tds/store.test-d.ts @@ -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) diff --git a/src/index.ts b/src/index.ts index 4d47b42e..1bcead4c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -154,7 +154,12 @@ export function makeStore< Id extends string, S extends StateTree, G extends Record> ->(id: Id, buildState: () => S, getters: G) { +>( + id: Id, + buildState: () => S, + // @ts-ignore + getters: G = {} +) { let store: CombinedStore | undefined function useStore(): CombinedStore {