forked from HackYourFuture/JavaScript3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
executable file
·56 lines (48 loc) · 1.49 KB
/
App.js
File metadata and controls
executable file
·56 lines (48 loc) · 1.49 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
47
48
49
50
51
52
53
54
55
56
'use strict';
{
const accounts = {
hyf: {
name: 'HackYourFuture',
type: 'org',
},
microsoft: {
name: 'Microsoft',
type: 'org',
},
jim: {
name: 'remarcmij',
type: 'user',
},
};
const { Model, HeaderView, RepoView, ContributorsView, ErrorView } = window;
const { createAndAppend } = window.Util;
class App {
constructor(account) {
const containers = App.renderContainers();
const model = new Model(account);
const fetchData = model.fetchData.bind(model);
model.subscribe(new HeaderView(account, containers.header, fetchData));
model.subscribe(new RepoView(containers.repo));
model.subscribe(new ContributorsView(containers.contributors));
model.subscribe(new ErrorView(containers.error));
fetchData();
}
static renderContainers() {
const root = document.getElementById('root');
const header = createAndAppend('header', root, { class: 'header' });
const error = createAndAppend('div', root);
const main = createAndAppend('main', root, {
class: 'main-container',
});
const repo = createAndAppend('section', main, {
class: 'repo-container whiteframe',
});
const contributors = createAndAppend('section', main, {
class: 'contributors-container whiteframe',
});
return { header, error, main, repo, contributors };
}
}
const ACCOUNT_KEY = 'hyf';
window.onload = () => new App(accounts[ACCOUNT_KEY]);
}