Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Cart Revamp #2522

Closed
lukeromanowicz opened this issue Mar 1, 2019 · 9 comments
Closed

[RFC] Cart Revamp #2522

lukeromanowicz opened this issue Mar 1, 2019 · 9 comments
Assignees
Labels
P1: Urgent Priority mark - high priority refactor Code refactoring RFC Request for comments
Milestone

Comments

@lukeromanowicz
Copy link
Contributor

lukeromanowicz commented Mar 1, 2019

Feature Name: Cart Revamp
Start Date: 2019-03-01
RFC PR: -

Summary:

Rewrite Cart to meet modern standards and good practices while keeping the backward compatibility.
With this module revamp we'd like to implement also some architectural and coding standards changes to keep the project feature-reach, tough flexible and easy to analyze.

Motivation

Because of the fast growth of Vue Storefront and adding multiple features over time, the core Cart module became extremely unmaintainable. It's not following many of basic standard, it is hard to test and finally, the code is hard both to read and unpredictable. It's a high time to redesign it and implement best practices which can be later spread across other modules.

Action plan:

  1. Define required changes
  • architecture design - collect, review and choose architectural changes to be implemented
  • code quality changes - fully utilize ES6+, follow best practices
  • code style and dev environment - choose a coding standard once and for all, guarded by software that will enforce its use (i.e. linter, prettier)
  1. Write integration tests that will help keep the backward compatibility after revamp
  2. Implement the changes including writing tests (TDD is welcome)
  3. Wrap the job up with docs and recommended solutions for often faced problems

Architecture changes

Code quality changes:

  • hard typing everything accordingly to Typescript Action plan
  • fully utilize ES6+ features like async and await, maps etc; use const instead of let where let is not necessary
  • keep in mind that actions are asynchronous and usually should return a promise whenever there is an async dispatch in an action
  • avoid keeping all the business logic store
  • no direct getting values to a global state from a scoped store - use getters
  • modifying state only through mutations
  • alphabetical sorting of vuex functions
  • keep a consistency of parameter types and naming
  • avoid using loggers - mutations and Vuex time travel are really powerful tools to help debugging the app, especially with a little love
  • if you really need to use loggers, place them in proper places (i.e. loging that shipping is going to be updated inside action updating shipping, not before that action)

Code style and dev environment


Please share your thoughts as every input is welcome and needed. Feel free to propose any changes that should be implemented in next-gen VSF modules. If you want to discuss the technical details regarding each point with a linked issue, please, post your thoughts in that issue instead of this topic to keep it clear. I'll update this RFC with conclusions as the discussion goes on.

@lukeromanowicz lukeromanowicz self-assigned this Mar 1, 2019
@lukeromanowicz lukeromanowicz added the RFC Request for comments label Mar 1, 2019
@pkarw
Copy link
Collaborator

pkarw commented Mar 1, 2019

I'm OK with this plan as we discussed it before :)

@pkarw pkarw pinned this issue Mar 1, 2019
@pkarw pkarw added refactor Code refactoring P1: Urgent Priority mark - high priority labels Mar 2, 2019
@filrak
Copy link
Collaborator

filrak commented Mar 2, 2019

Looks awesome and It's a really good plan! Please start first with an abstract overview of how every action should look like before doing actual implementation. We should also keep c ;)

I don't agree with two points though:

avoid using loggers - mutations and Vuex time travel are really powerful tools to help debugging the app, especially with a little love

Right now it's not DX friendly due to massive number of mutations happening on every action therefore Logger is more useful right now. I really like the examples from the article you sent tho but we need to keep in mind that mutations and actions will be merged in the future versions of Vuex. I suggest making use of action subscribing in Logger as the extension to vue devtools mutations time traveling but this is totally separate topic to discuss.

Also thing that is really important is consistency in names and params of mutations/actions across different modules responsible for similar operations (like listing single product/category, reading/writing cache, receiving the data without mutating state etc). We should have dedicated helpers for such typical use cases and common name/param conventions so every Vuex module is similar on some level of abstraction

Overally great job! I'm really looking forward to see first results!

@ResuBaka
Copy link
Collaborator

Some news on the Code Style/Rules. Because i would like to implement prettier. When you have information about it. I would be glad to implement it.

@lukeromanowicz
Copy link
Contributor Author

@ResuBaka it's not done in 1.9 and there is only a slight chance that I will find enough time to discuss and do it in 1.10.

@ResuBaka
Copy link
Collaborator

I have made a small POC where i need some feedback of how the eslint settings should look like.
Should i make a PR for the changes and in there the changes that still need to be done to the eslint or should these be done here in the Ticket?

One of the settings that could be changed is space-before-function-paren. This setting could be changed to ["warn", "never"] or ["error", "never"] as prettier removes all spaces between function name and the opening paren.

@pkarw
Copy link
Collaborator

pkarw commented Apr 17, 2019

@lukeromanowicz we need you in here I guess :)

@lukeromanowicz
Copy link
Contributor Author

@ResuBaka
The early version looks very promising. Changes made by prettier look similar to what our ESlint would expect. Please implement also the TSlint and make a PR. We can implement it as solution to #1477

@ResuBaka ResuBaka mentioned this issue May 1, 2019
8 tasks
pkarw added a commit that referenced this issue May 29, 2019
…inistic cart sync behaviors + refactor to async/await #2964
@pkarw
Copy link
Collaborator

pkarw commented Jun 5, 2019

Partially done within https://github.com/DivanteLtd/vue-storefront/pull/2887/files:

  • fully utilize ES6+ features like async and await, maps etc; use const instead of let where let is not necessary
  • keep in mind that actions are asynchronous and usually should return a promise whenever there is an async dispatch in an action
  • no direct getting values to a global state from a scoped store - use getters
  • modifying state only through mutations
  • keep a consistency of parameter types and naming

@pkarw
Copy link
Collaborator

pkarw commented Jun 6, 2019

Closing with the #2887 as for now. Looking for the first developers' feedback to adjust the further refactoring plans. We still need to upgrade the unit tests - which topic has been covered by the new issue #3023

@pkarw pkarw closed this as completed Jun 6, 2019
@pkarw pkarw added this to the 1.10.0-rc.1 milestone Jun 6, 2019
@pkarw pkarw unpinned this issue Jun 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1: Urgent Priority mark - high priority refactor Code refactoring RFC Request for comments
Projects
None yet
Development

No branches or pull requests

4 participants