Skip to content

Commit

Permalink
wip: pinia
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Dec 16, 2019
1 parent 0056507 commit 6bb041b
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/pinia.ts
Original file line number Diff line number Diff line change
@@ -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<
Expand Down Expand Up @@ -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,
Expand All @@ -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,
}
}

0 comments on commit 6bb041b

Please sign in to comment.