Skip to content

Make USC framework agnostic with redux #177

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

Closed
wants to merge 197 commits into from
Closed

Make USC framework agnostic with redux #177

wants to merge 197 commits into from

Conversation

dayhaysoos
Copy link
Owner

This is a very rough start to getting redux into use-shopping-cart.

We're calling the redux part of this the core of the lib.

Some major changes I've been making:

Entry Class

use-shopping-cart has an Entry class that is important to making sure the cartDetails is always formatted properly. From the Entry class, we use functions like createEntry, updateEntry, removeEntry.

I'm copying this class and those functions to the core directory, however, I'm changing the arguments to accept an object rather than a bunch of arguments. It's much easier to manage/digest this way imo

Major API changes

  • addItem, instead of taking 4 arguments, now takes 2. The first argument is the product (an Object) and the second param is an options Object that will take optional count, price_metadata, product_metadata

To Do

  • There is no support for local storage so far. I think redux-persist would be a great option, just not sure how it'll look
  • Set up better tests? I think the tests so far are doing what they should, I just feel like there could be ways to make configuring and setting up easy.

I'm hoping to get lots of feedback on this about anything 🙏

@github-actions github-actions bot added example Changes to examples for use-shopping-cart package Changes to use-shopping-cart package labels Feb 24, 2021
Copy link
Collaborator

@andria-dev andria-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks pretty good so far.

A few notes on the core implementation:

It looks like we're missing some things that we have in the current react-based implementation. Here are all the methods/actions we do and don't have.

  • addItem
  • incrementItem
  • decrementItem
  • setItemQuantity
  • updateQuantity
  • loadCart
  • redirectToCheckout
  • checkoutSingleItem
  • handleCartClick
  • handleCartHover
  • handleCloseCart

I think we also need to add the formattedTotalPrice getter.

Other stuff

All of the exported values will need type definitions (I'll leave it up to you if you just want to switch it to TypeScript or write .d.ts files) but we can wait to add those until everything is finalized. And, we'll need to change the React implementation we have to use the Redux store, it'll act as a sort of wrapper around it so that the React API for this library stays similar.

Also, we can probably move the util.js file and stuff it has into the core/ directory. Serverless function stuff could have its own serverless/ directory if we wanted.

@dayhaysoos
Copy link
Owner Author

@ChrisBrownie55 I just updated all the tests, it's a little messy and there's prob some stuff that could be done better, but for the most part, actions and reducers have tests that I think are pretty solid. I think I'm gonna start writing tests for the Entry classes as well unless you think that might be redundant.

@andria-dev
Copy link
Collaborator

@dayhaysoos Yeah, that might be a bit redundant. We should already have complete test coverage for the Entry code based on tests for everything else.

@dayhaysoos
Copy link
Owner Author

Hey @andria-dev, I just wanted to bring to your attention that I merged this branch into dev (not sure if I should have done that or not tbh). Should we continue pushing to this one or should merge the new changes to dev and close this PR?

Also, I like your new name!

@andria-dev
Copy link
Collaborator

Hi @dayhaysoos, thanks for letting me know, we can merge these into the dev branch. We should probably set up a PR for the dev branch to be merged into the main branch eventually though.

Thank you! 😊

@dayhaysoos
Copy link
Owner Author

Closing this as everything has been moved into dev branch

@dayhaysoos dayhaysoos closed this Jul 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request example Changes to examples for use-shopping-cart package Changes to use-shopping-cart package release Indicates a new version release testing Related to testing of this package tests Changes to tests in use-shopping-cart
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make use-shopping-cart framework agnostic with Redux
4 participants