Skip to content

Instantly share code, notes, and snippets.

@FlorianWendelborn
Created January 24, 2019 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlorianWendelborn/4679e711b702785580cb499b217b690d to your computer and use it in GitHub Desktop.
Save FlorianWendelborn/4679e711b702785580cb499b217b690d to your computer and use it in GitHub Desktop.
const mapBranchesGetter = <G extends keyof BranchesStore>(
getter: G
): BranchesStore[G] => {
return this.context.rootGetters[`branches/${getter}`]
}
const getBranch = mapBranchesGetter('getBranch')
const mapGetter = <S, G extends keyof S>(namespace: string, getter: string): S[G] => {
return this.context.rootGetters[`${namespace}/${getter}`]
}
const gB = mapGetter<BranchesStore, 'getBranch'>('branches', 'getBranch')
const mapGetter = <S, G extends keyof S>(store: S, getter: G): S[G] => {
return this.context.rootGetters[`${(store as any).namespace}/${getter}`]
}
const getBranch = mapGetter(BranchesStore, 'getBranch')
interface Store {
namespace: string
}
const mapGetter = <S>(store: Store) => <G extends keyof S>(
getter: G
): S[G] => this.context.rootGetters[`${store.namespace}/${getter}`]
const mapBranchesGetter = mapGetter<BranchesStore>(BranchesStore)
const getBranch = mapBranchesGetter('getBranch')
const mapGetter = <S>(namespace: string) => <G extends keyof S>(
getter: G
): S[G] => this.context.rootGetters[`${namespace}/${getter}`]
const getBranch = mapGetter<BranchesStore>('branches')('getBranch')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment