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

fix(venia): rm staleGuestCartId on error #354

Merged
merged 5 commits into from
Oct 19, 2018

Conversation

zetlen
Copy link
Contributor

@zetlen zetlen commented Oct 12, 2018

Fixes #344.

The error was caused by a stale guestCartId whose corresponding cart in the API was no longer available. Since we don't have GraphQL for sessions yet, the guestCartId is stored in localStorage as well as in the Redux store. We were clearing it from localStorage on error, but forgetting to clear it from the store itself.

This fixes that!

This PR is a:

[ ] New feature
[ ] Enhancement/Optimization
[ ] Refactor
[x] Bugfix
[ ] Test for existing code
[ ] Documentation

@coveralls
Copy link

coveralls commented Oct 12, 2018

Coverage Status

Coverage remained the same at 15.873% when pulling 123a35f on zetlen/fix-cart-retry-cycle into b32ff43 on release/2.0.

* aramis: true
* };
*
* console.lot(omit(musketeers, 'athos'));
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it should be console.log()

module.exports = (obj, omitKey) =>
Object.entries(obj).reduce(
(out, [key, value]) =>
key === omitKey ? out : ((out[key] = value), out),
Copy link
Contributor

Choose a reason for hiding this comment

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

I propose to follow functional paradigm and do not mutate function arguments.

(out, [key, value]) => key === omitKey ? out :  { ...out, [key]: value }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this implementation, the spread operator creates a new object and does not mutate the existing one.

However, there are other places where we do mutate intermediate results during a reduce operation. I consider these acceptable because they are local mutations only, to an object which is not exposed to the outside closure.

* }
*/

module.exports = (obj, omitKey) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, James, are you sure that we need to add custom implementation of omit function to the project? My personal opinion, that it will be better to add lodash or underscore to the project. This libraries contains a lot of useful methods, that we will need in our app in the future like omit. If we decide to write our own implementations of such methods, than we will have to maintain our code, cover it with tests, write docs etc. Lodash is very popular library. The only thing we should remember is to avoid imports import _ from 'lodash'; and just write, for example, import omit from 'lodash/omit';

Copy link
Contributor

Choose a reason for hiding this comment

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

By the way, it will be useful to add ability to pass an array of omitKeys to the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my experience, Lodash adds a lot of file size, even when using tree-shaking. There are a few places in Venia and Peregrine where a Lodash method might be useful, but so far we have avoided its use. But I could be persuaded!

If you think that Lodash would ultimately help the codebase, then I would love for you to create a branch, refactor those parts of Venia and Peregrine to use Lodash, make sure they do not increase bundle size, and open a pull request!

@zetlen
Copy link
Contributor Author

zetlen commented Oct 16, 2018

@Starotitorov We may still decide to use Lodash in a few places, because you're right that we need to maintain as little code as possible. But for this PR, I realized that the standard in other reducers was to use an ES7 object spread and set the property to null, so I changed it to that. There's no longer any need for an omit function!

Please review again when you have time.

Copy link
Contributor

@Starotitorov Starotitorov left a comment

Choose a reason for hiding this comment

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

Looks good to me

@mhhansen
Copy link
Contributor

mhhansen commented Oct 18, 2018

will double check in short to see if #344 stills reproduce
EDIT was already resolved by 314

@pcvonz
Copy link
Contributor

pcvonz commented Oct 18, 2018

looks good! 👍

@zetlen zetlen merged commit e6f4d46 into release/2.0 Oct 19, 2018
@supernova-at supernova-at deleted the zetlen/fix-cart-retry-cycle branch July 25, 2019 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants