From: Eduardo San Martin Morote Date: Fri, 19 Mar 2021 14:31:19 +0000 (+0100) Subject: test: add missing file X-Git-Tag: v0.3.0~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=40a1d564ca77603f8e0dcef5838e201216213da9;p=thirdparty%2Fvuejs%2Fpinia.git test: add missing file --- diff --git a/src/mapHelpers.ts b/src/mapHelpers.ts new file mode 100644 index 00000000..6eff181b --- /dev/null +++ b/src/mapHelpers.ts @@ -0,0 +1,28 @@ +import { GenericStoreDefinition, Store, StoreDefinition } from './types' + +type StoreObject = S extends StoreDefinition< + infer Ids, + infer State, + infer Getters, + infer Actions +> + ? { + [Id in Ids]: () => Store + } + : {} + +type Spread = A extends [infer L, ...infer R] + ? StoreObject & Spread + : unknown + +export function mapStores( + ...stores: [...Stores] +): Spread { + return stores.reduce((reduced, useStore) => { + // @ts-ignore + reduced[useStore.$id] = function () { + return (useStore as GenericStoreDefinition)((this as any).$pinia) + } + return reduced + }, {} as Spread) +}