London | 26-ITP-May | Martin Mwaka | Sprint 2 | Book library - #523
London | 26-ITP-May | Martin Mwaka | Sprint 2 | Book library#523Temceo wants to merge 8 commits into
Conversation
…dd console 4. correct was read message
…submit as this should be done in JavaScript
…Button variable and eventListener
…js - update to accept populate table from fragment and refactor to make content easier to understand - style.css - add css for delete book message
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
cjyuan
left a comment
There was a problem hiding this comment.
Can you check if any of this general feedback can help you further improve your code?
https://github.com/CodeYourFuture/Module-Data-Flows/blob/general-review-feedback/debugging/book-library/feedback.md
Doing so can help me speed up the review process. Thanks.
|
I have reviewed the general feedback and improved the code |
| addBookForm.addEventListener("submit", (event) => { | ||
| event.preventDefault(); | ||
| processEntries(); | ||
| }); |
There was a problem hiding this comment.
To make locating all the "code that is to be executed once on page load" easier, a common practice is to keep the code in the same place. For example, inside the page's onload callback function.
There was a problem hiding this comment.
Hi, can I please clarify on this point. The addForm event listener only runs each time a new book is added and the processEntries() function validates the inputs before adding the new book. The code that is run on page load is the populateStorage() function which calls the render() function to show all existing books in the library
There was a problem hiding this comment.
I have updated the event listeners for window load and add book so hopefully now it is much clearer
There was a problem hiding this comment.
- Basically all statements written in the top-level scope are code that would be executed once when the HTML page first loaded.
- Code that attach a callback to a DOM element once usually falls into this category.
- Typically we order the code in a file the following manner:
variable declarations
function definitions
code to be executed (code to be executed once is placed here)
- Alternatively, we can place all the code to be executed once on page load inside a function (e.g.,
init()), and then just call the function.
What you did works.
The code that manages form validation could be better organised but that's out of the scope of this exercise.
| addBookForm.addEventListener("submit", (event) => { | ||
| event.preventDefault(); | ||
| processEntries(); | ||
| }); |
There was a problem hiding this comment.
- Basically all statements written in the top-level scope are code that would be executed once when the HTML page first loaded.
- Code that attach a callback to a DOM element once usually falls into this category.
- Typically we order the code in a file the following manner:
variable declarations
function definitions
code to be executed (code to be executed once is placed here)
- Alternatively, we can place all the code to be executed once on page load inside a function (e.g.,
init()), and then just call the function.
What you did works.
The code that manages form validation could be better organised but that's out of the scope of this exercise.
| addBookForm.reset(); | ||
| addBook.reset(); |
There was a problem hiding this comment.
Why not use the name addBookForm? It makes it clearer that the variable refers to a form element.
There was a problem hiding this comment.
I have reverted this to addBookForm
| pagesInput.value, | ||
| trimmedTitle, | ||
| trimmedAuthor, | ||
| trimmedPages, |
There was a problem hiding this comment.
Should the .pages property of a book be a number or a string? For this particular simple app it may not matter but it is safer to consistently represent a kind of data using same data type.
Self checklist
Changelist
Debug and improve functionality of the library app