Skip to content

Update Shopping Cart Example #1109

Closed
Closed
@hootlex

Description

@hootlex

What problem does this feature solve?

The goal of updating the example is to make it more friendly to newcomers and also demonstrate some best practices.

What does the proposed API look like?

After reviewing the shopping cart example and discussing it with @chrisvfritz, I’ve started working on possible improvements.

Summary

  • Use separate mutations to update the checkout status and the cart.
  • Move/create cart related getters to the cart module.
  • Remove abbreviations
  • Make the example comply with the style guide.
  • Make mutations responsible for updating one piece of state to make debugging easier.
  • Use an action (addProductToCart) to commit separate mutations on cart and products modules instead of using a shared mutation.
  • Remove mutation types.
  • Remove getters that return a piece of the state as is.
  • Make modules namespaced
  • Rename state properties

Discussion

Mutation types

What do you think of removing the mutation types in order to make the example simpler? Mutation types might be beneficial in some cases but by not using them in the example might make it more friendly to newcomers.

Remove getters that return a piece of state as is

I feel that this pattern might give the wrong impression to newcomers that they always have to use a getter in order to access the state.
Example:

const getters = {
  allProducts: state => state.all
}

Other

I think that we could use more descriptive names in Vuex assets.
For instance added can be cartItems or just items since it’s being accessed as cart.items. In general, I like the items convention for all modules. This way I always know the property name and distinguish the content based on the module name. For example users.items, products.items​.

Also, addToCart could be addProductToCart since a cart can also contain other things.

That might be too peaky but I believe that when people go over an official example it’s very likely to use it as a reference for best practices.

What do you think? 🙂

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