From: Eduardo San Martin Morote Date: Mon, 16 Dec 2019 08:27:44 +0000 (+0100) Subject: wip: pinia X-Git-Tag: 0.1.0-alpha.0~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6bb041b839d904c5f2380fbe12bba427a00ab9e7;p=thirdparty%2Fvuejs%2Fpinia.git wip: pinia --- diff --git a/src/pinia.ts b/src/pinia.ts index ce7d9375..24f22188 100644 --- a/src/pinia.ts +++ b/src/pinia.ts @@ -1,5 +1,5 @@ import { Store, StoreGetter, StateTree, StoreGetters } from './types' -import { CombinedStore } from './store' +import { CombinedStore, buildStore } from './store' export type CombinedState< S extends Record< @@ -43,6 +43,26 @@ export type CombinedGetters< : never } +function buildCombinedStore< + S extends Record< + string, + CombinedStore>> + > +>(stores: S): Store<'', CombinedState> & CombinedGetters { + const state = {} + for (const name in stores) { + const store = stores[name] + Object.defineProperty(state, name, { + get: () => store.state, + }) + } + + // @ts-ignore + return { + state, + } +} + export function pinia< S extends Record< string, @@ -56,7 +76,16 @@ export function pinia< > >(stores: S): Store<'', CombinedState> & CombinedGetters { // TODO: implement if makes sense + const state = {} + for (const name in stores) { + const store = stores[name]() + Object.defineProperty(state, name, { + get: () => store.state, + }) + } // @ts-ignore - return {} + return { + state, + } }