From 18b5756b97d4551acc18667468be60e524159bbf Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Mon, 25 Nov 2019 16:06:05 +0100 Subject: [PATCH] feat: make getters optional --- __tests__/pinia/stores/cart.ts | 3 +-- __tests__/pinia/stores/combined.ts | 4 ++-- __tests__/pinia/stores/user.ts | 1 - __tests__/tds/store.test-d.ts | 13 +++---------- src/index.ts | 7 ++++++- 5 files changed, 12 insertions(+), 16 deletions(-) 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 { -- 2.47.2