Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

code added: press Update basket button updates item in cart database. #69

Merged

Conversation

richardnwinder
Copy link
Contributor

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().

});
}
// function updateCart()
// for each item row in cart table call updateToCart (client.js - updateToCart(itemId, quantity, callback))
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed.

location.reload();
}
}
next();
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

@richardnwinder
Copy link
Contributor Author

I also removed conflicting functions by nustiueudinastea. Is this good etiquet, or should it be discussed first?

@philwinder
Copy link
Contributor

That's fine, so long as they perform an equivilent job.

Copy link
Contributor

@nustiueudinastea nustiueudinastea left a comment

Choose a reason for hiding this comment

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

LGTM

@nustiueudinastea nustiueudinastea merged commit 1231715 into microservices-demo:master Mar 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants