HerringtonDarkholme / kilimanjaro

typed vuex 2.0
62 stars 4 forks source link

[Feature] actions/getters/mutations #5

Closed HerringtonDarkholme closed 7 years ago

HerringtonDarkholme commented 8 years ago

These method can define multiple items in kilimanjaro.

store.getters(p => ({
  coffee: p(state => state.cappuccino),
  remainingAnko: p(state => state.ankoAmount - state.matchaAmount)
}))
.mutations(p => ({
  payCheck: p(state => () => state.order += 1),
  eat_sweet: p(state => n => state.ankoAmount -= n)
}))

This requires mapping types, index access type and keyof typings. The p place holder is mainly for type checking. Because TypeScript cannot index accessed type for return type. Also requires index access type on type constraints.

HerringtonDarkholme commented 7 years ago

isomorphic mapped types can enable this feature

store.getters<P>(config: {[K in keyof P]: (s: state) => P[K]})
HerringtonDarkholme commented 7 years ago

Very hard to implement since overloading choosing is too finicky in TypeScript. 😞 Need to split two API

HerringtonDarkholme commented 7 years ago

Shipped in 0.6.0