-
Notifications
You must be signed in to change notification settings - Fork 2.2k
code added: press Update basket button updates item in cart database. #69
code added: press Update basket button updates item in cart database. #69
Conversation
}); | ||
} | ||
// function updateCart() | ||
// for each item row in cart table call updateToCart (client.js - updateToCart(itemId, quantity, callback)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says foreach, but this code isn't wrapped in a loop.
Also, the next
function defined below is only called once. So it can be inlined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was just english description not program language description. Although I did implement foreach to start with until I realised callbacks were far better way to implement.
// cart/update request sent to frontend server (index.js - app.post("/cart/update" function...) | ||
function updateToCart(id, quantity, next) { | ||
|
||
console.log("Sending request to update cart: item: " + id + " quantity: " + quantity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably best to remove this log message so we don't spam the user's console with "ok" messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
location.reload(); | ||
} | ||
} | ||
next(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to only be called once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a good idea. It is the entry point to the callback routine that is called recursively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which method is called recursively? I can't see it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, next is passed into updateToCart
as a callback, above.
I also removed conflicting functions by nustiueudinastea. Is this good etiquet, or should it be discussed first? |
That's fine, so long as they perform an equivilent job. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
basket.html - updateCart() function recursively calls client.js - updateToCart() function which in turn posts to the frontend server with each item update. On return from the server the updateToCart() function calls the next recursion of the updateCart() function. Once the recursion is complete it returns with a location.reload().