-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
34 lines (28 loc) · 1001 Bytes
/
controller.js
File metadata and controls
34 lines (28 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function Controller(model, view){
this.model = model;
this.view = view;
this.init();
}
Controller.prototype.init = function(){
this.addHandlerForAddTask();
}
Controller.prototype.addHandlerForAddTask = function(){
/*1. получить значение из инпута
2. получить кнопку, к которой нужно добвить событие вью
! 2.5 создать обработчик, который будет добавлять значение в модель
3. повесить событие на кнопку
4. положить значение в модель
5. вызвать рендер с новым вью
*/
let button = this.view.elements.addButton;
button.addEventListener('click', this.addTask.bind(this));
}
Controller.prototype.addTask = function(){
let value = this.view.elements.input.value;
if(!value) {
return;
}
this.model.addTodoItem(value);
this.view.render(this.model.data);
this.view.elements.input.value = '';
}