ITurres/Task-Manager

Issue #2: JavaScript best practices

Closed this issue · 0 comments

Functions:

  • Please consider not using flags as parameters because they are telling you that the function is doing more than it should.

  • 📂* src/js/markup-injectors/

    • **📄update-tasklist-dom-injection.js

      Although the parameter is not a flag/Boolean, it is intended to work as such, I would recommend splitting this function in two, e.g. injectTaskListOnDOM for the whole list of items and another injectLastTaskItemOnDOM just for the last item.


  • A function should do one thing. Avoid executing multiple actions within a single function.

  • 📂* src/js/user-controller/

    • **📄user-controller.js

      • Line 18; updateTask() method.

      Consider splitting this method into two separate methods, one for updating the Task's description/content String and another for updating the Task's complete Boolean.


  • Use conditional shorthand. This might be trivial, but it's worth mentioning. Use this approach only for Boolean values and if you are sure that the value will not be undefined or null.

  • 📂* src/js/utils/

    • **📄updateCompletedTaskStyles.js

          // Line 5
      
       5| if (JSON.parse(taskCheckboxInput.dataset.completed) === true) {
      
         //Could be changed to:
          
       5| if (JSON.parse(taskCheckboxInput.dataset.completed)) {

For more info visit JavaScript Clean Code - Best Practices