forked from HackYourFuture/JavaScript3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeaderView.js
More file actions
executable file
·46 lines (39 loc) · 1.06 KB
/
HeaderView.js
File metadata and controls
executable file
·46 lines (39 loc) · 1.06 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
{
const { createAndAppend } = window.Util;
class HeaderView {
constructor(account, header, fetchData) {
this.account = account;
this.header = header;
this.fetchData = fetchData;
this.select = null;
}
update(state) {
if (!this.select && !state.error) {
this.render(state.repos);
}
}
/**
* Renders the data for the 'select' message type. Create a <select> element
* and its <option> children.
* @param {Object[]} repos An array of repository objects.
*/
render(repos) {
createAndAppend('div', this.header, { text: this.account.name });
this.select = createAndAppend('select', this.header, {
class: 'repo-select',
autofocus: 'autofocus',
});
repos.forEach(repo =>
createAndAppend('option', this.select, {
text: repo.name,
value: repo.id,
}),
);
this.select.addEventListener('change', () =>
this.fetchData(this.select.value),
);
}
}
window.HeaderView = HeaderView;
}