From: Eduardo San Martin Morote Date: Fri, 19 Mar 2021 14:31:19 +0000 (+0100) Subject: test: add missing file X-Git-Tag: v2.0.0-alpha.11~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2037a53d6c8e56dc13e032f1d73254e59b4b1c2;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) +}