]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
wip: pinia
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 16 Dec 2019 08:27:44 +0000 (09:27 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 16 Dec 2019 08:27:47 +0000 (09:27 +0100)
src/pinia.ts

index ce7d937567ccadd4f3951c461474a64ebc9097cb..24f22188461eaec13bfb7eb921e360d725d7ba57 100644 (file)
@@ -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<string, StateTree, Record<string, StoreGetter<StateTree>>>
+  >
+>(stores: S): Store<'', CombinedState<S>> & CombinedGetters<S> {
+  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<S>> & CombinedGetters<S> {
   // 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,
+  }
 }