Vuex-module-decorators: How to get arguments passed to getters

Created on 9 Dec 2018  路  5Comments  路  Source: championswimmer/vuex-module-decorators

How to get arguments passed to getters

for example:

const state = {
 users:[{id:1},{id:2}]
}
const getters = {
  getUser: state => id => state.users.find( el =>el.id == id )
}

Most helpful comment

@Module
class MyModule extends VuexModule {
  users = [{id:1},{id:2}]
  get user () {
    return (id => this.users.find( el =>el.id == id ))
  }
}

All 5 comments

@Module
class MyModule extends VuexModule {
  users = [{id:1},{id:2}]
  get user () {
    return (id => this.users.find( el =>el.id == id ))
  }
}

Was about to close it thanks any way

Oh I didn't realise you are the same person I replied on Twitter too 馃槅

Thanks a lot for this guys. May I suggest to include this example also in the project's tests? I was googling everywhere for this, but couldn't find the solution. Only when I wanted to create a new issue on this project, I've noticed this one.

I鈥檓 all for better documentation, but this is literally the same thing as you鈥檇 do in normal Vuex, but you just return it instead of using an arrow function. Not sure what鈥檚 confusing about it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blackmad picture blackmad  路  4Comments

Leandro-Albano picture Leandro-Albano  路  3Comments

championswimmer picture championswimmer  路  6Comments

darthf1 picture darthf1  路  5Comments

webcoderkz picture webcoderkz  路  6Comments