Created
January 24, 2019 23:58
-
-
Save FlorianWendelborn/4679e711b702785580cb499b217b690d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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