Skip to content

Homework#5 [Done] #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

TigranKirakosov
Copy link

No description provided.

};
var ctrlToggleTask = function(event) {
var itemID, splitID, ID, icon;
if (event.target.className === DOM.uncheckedBtn || DOM.checkedBtn) {

Choose a reason for hiding this comment

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

if you wanna check that className of target equals to DOM.uncheckedBtn or DOM.checkedBtn you should write another condition, because current condition checks if className equals to DOM.uncheckedBtn or DOM.checkedBtn isn't equal to boolean false ( isn't empty string, undefined, 0 and so on)

Copy link
Author

Choose a reason for hiding this comment

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

In current case, all I want to do is to check if event.target.className matches any of these certain classNames. Isn't that correct if there's no match the boolean result is false?

Choose a reason for hiding this comment

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

yeah, it's correct, but I meant that your condition isn't correct - try in console if (1 === 2 || 3) console.log('oh!')

Copy link
Author

Choose a reason for hiding this comment

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

Now I see. To be correct, I should've done code like this, I suppose: if (1 === 2 || 1 === 3) console.log('oh')

icon = event.target;
}
if (itemID) {
splitID = itemID.split('-');

Choose a reason for hiding this comment

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

move this logic to separated function getItemInfo that returns object with 2 fields - type and id

DOM = UICtrl.getDOMStrings();
tasks = storageCtrl.getFromLS();
filterValue = document.querySelector(DOM.filterInput).value;
if (filterValue === 'no filter') {

Choose a reason for hiding this comment

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

move no filter value to some object with constants

newTask = new Task(ID, text, deadline);
return newTask;
},
addToLS: function(task) {

Choose a reason for hiding this comment

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

why both functions - addTask and addToLS are public api of storageController? - I think you need to extract all logic that is responsible for interactions with localStorage to separated controller/service and use it inside your storageController

Copy link
Author

Choose a reason for hiding this comment

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

Will do that, valuable suggestion, should've separated the logic

return newTask;
},
addToLS: function(task) {
tasks.push(task);

Choose a reason for hiding this comment

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

why addToLS function makes more than just add task to LS? - in fact, you sync your internal state firstly and then add new state to LS. I think you need to move this logic to addTask function. current implementation of addTask function better to rename to smth like createTask

Copy link
Author

Choose a reason for hiding this comment

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

I see, will fix that

this.iconClass = DOM.uncheckedBtn;
};
Task.prototype.toggleState = function() {
if (this.isDone === 'undone') {

Choose a reason for hiding this comment

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

move strings done and undone to some object with constants

filteredTasks = tasks.filter(function(task) {
return task.deadline == filterValue || task.isDone == filterValue;
});
filteredTasks.forEach(function(task) {

Choose a reason for hiding this comment

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

move this logic to functions renderTasks and renderTask

var html = '';
tasks = storageCtrl.getFromLS();
taskList = document.querySelector(DOM.taskList);
tasks.forEach(function(task) {

Choose a reason for hiding this comment

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

use just renderTasks function that I mentioned in comment above here instead of code duplication

icon.className = DOMStrings.checkedBtn;
}
},
filterTasks: function(tasks) {

Choose a reason for hiding this comment

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

why UI controller should know how to filter data? As I can see in your to do list UIController - it's classic view component. All what should do this controller - correctly display data to user. Filtering of the data should do controller (line 145) component and just put array of filtered tasks to UI controller

.querySelector(DOM.submitBtn)
.addEventListener('click', ctrlAddTask);
document.addEventListener('keypress', function(event) {
if (event.keyCode === 13 || event.which === 13) {

Choose a reason for hiding this comment

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

move keycode 13 to constants

Copy link
Author

Choose a reason for hiding this comment

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

Okay, thanks!

@TigranKirakosov TigranKirakosov changed the title Homework#5 [Ready] Homework#5 [Done] Aug 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants