refactor according to comments on previous prs#12
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
|
||
| if (lineIds.length === 1) { | ||
| cartState = await removeCartItem(lineIds[0]!); | ||
| } else if (lineIds.length > 1) { |
There was a problem hiding this comment.
Vercel API suggests that lineIds is string[]. For that reason we use if/else statement at the first place and now we have this check for more than 1 IDs.
As I get it actually we can't remove more than one line at a time, so actually we always get array of one Id and I'm thinking if it's safe to simplify this logic by keeping only cartState = await removeCartItem(lineIds[0]!) or smth similar.
As a safety measure we always can leave it as it is but I don't see cases when else if block will be executed...
@BC-krasnoshapka, what's your thought on this? 🤔
There was a problem hiding this comment.
I suggest we leave it as is now, because core expects it to be array, thus we have to support array.
| }); | ||
| const collectionIdList = res.body.data.site.categoryTree.map(({ entityId }) => entityId); | ||
|
|
||
| const collections = await Promise.all( |
There was a problem hiding this comment.
Regarding fetching all categories via single query. In theory, we could use categoryTree query for one request but Vercel Collection requires SEO field that we can get via Category node.
There was a problem hiding this comment.
OK, I see the problem, let's leave it as is then.
|
|
||
| if (lineIds.length === 1) { | ||
| cartState = await removeCartItem(lineIds[0]!); | ||
| } else if (lineIds.length > 1) { |
There was a problem hiding this comment.
I suggest we leave it as is now, because core expects it to be array, thus we have to support array.
| }); | ||
| const collectionIdList = res.body.data.site.categoryTree.map(({ entityId }) => entityId); | ||
|
|
||
| const collections = await Promise.all( |
There was a problem hiding this comment.
OK, I see the problem, let's leave it as is then.
What / Why
This PR adds small improvements on few methods based on previously left comments.
Proof
Tested locally