Skip to content

Vuex getters #145

@ruiposse

Description

@ruiposse

Hi guys. There's been something on my mind lately about Vuex that I'll try my best to explain here.

I understand that Vuex getters are meant to return a sub-set of the state and that's fine. I also kinda understand why they can't take arguments... because reasons (SSR) and stuff.

On a component, if I want to return, say, a product from the state I'd access it directly, something like state.products[productId] and that it would be fine.

Now say I would like to return a product by productName instead and let's say I would do it by iterating on the product array state until I find it. This is still fine and I would create a method on the component to deal with it. If I would like to share getProductByName method, I would put it onto a mixin and everything would be alright.

But... Wouldn't it be nicer if Vuex could provide me with a way of creating a file of "special" getters so that everything state related (even just reading that state) would be managed on the "Vuex side of things" ?

I think that literally what I'm saying is that Vuex could have a way of letting me pass arguments to "getters". Just for example sake, current getters would become reducers (because they return a sub-set of the state) and then the "new" getters would actually be able to take arguments to compute off. (I'm totally aware that renaming is not an option, since it would break compatibility, but hopefully it was useful for an argument sake) (also, sorry about reducers naming, because I didn't want to start a discussion on what Flux is not and what Vuex is 😄 ).

Any thoughts ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions