@@ -58,42 +58,55 @@ Instructions:
58584 . Move your existing code responsible for initializing your application to the ` constructor ` of the ` View ` class.
59595 . The bulk of your remaining code should probably go to the ` fetchAndRender() ` method of the ` View ` class.
6060
61- ### Skeleton
61+ ### Suggested skeleton
6262
63- Use this skeleton as overall design for your code in ` app.js ` :
63+ You could use this skeleton as overall design for your code in ` app.js ` :
6464
6565``` js
6666' use strict' ;
6767{
6868 const hyfUrl = ' https://api.github.com' ;
6969 const hyfReposUrl = hyfUrl + ' /orgs/HackYourFuture/repos?per_page=100' ;
70- const repoUrl = hyfUrl + ' /repos/HackYourFuture/' ;
7170
7271 class Repository {
7372 constructor (data ) {
74- this .data = data;
73+ this ._data = data;
7574 }
7675
7776 /**
78- * Render the repository info into the DOM.
79- * @param {HTML element} parent The parent element in which to render the repository
77+ * Render the repository info to the DOM.
78+ * @param {HTML element} parent The parent element in which to render the repository.
8079 * info.
8180 */
8281 render (parent ) {
8382 // Add your code here.
84- // This method should render the repository data stored in the 'data ' property
83+ // This method should render the repository data stored in the '_data ' property
8584 // as HTML elements and append them to the `parent` element.
8685 }
86+
87+ /**
88+ * Returns an array of contributors as a promise
89+ */
90+ fetchContributors () {
91+ // Add your code here
92+ }
93+
94+ /**
95+ * Returns the name of the repository
96+ */
97+ name () {
98+ // Add your code here
99+ }
87100 }
88101
89102 class Contributor {
90103<
7440
/code> constructor (data ) {
91- this .data = data;
104+ this ._data = data;
92105 }
93106
94107 /**
95- * Render the contributor info into the DOM.
96- * @param {HTML element} parent The parent element in which to render the contributor
108+ * Render the contributor info to the DOM.
109+ * @param {HTML element} parent The parent element in which to render the contributor.
97110 * info.
98111 */
99112 render (parent ) {
@@ -105,6 +118,13 @@ Use this skeleton as overall design for your code in `app.js`:
105118
106119 class View {
107120 constructor () {
121+ this .initialize ();
122+ }
123+
124+ /**
125+ * View initialization
126+ */
127+ async initialize () {
108128 // Add code here to initialize your app
109129 // 1. Create the fixed HTML elements of your page
110130 // 2. Make an initial XMLHttpRequest to populate your <select> element
@@ -115,29 +135,24 @@ Use this skeleton as overall design for your code in `app.js`:
115135 * information as HTML elements in the DOM
116136 * @param {*} repoName The name of the selected repository
117137 */
118- fetchAndRender (repoName ) {
138+ async fetchAndRender (repoName ) {
119139 const leftDiv = ... ;
120140 const rightDiv = ... ;
121141
122142 // ...
123143
124- this .fetchJSON (repoUrl + repoName)
125- .then (repoInfo => {
126- const repo = new Repository (repoInfo);
127- return this .fetchJSON (repoInfo .contributors_url )
128- .then (contributors => {
129- repo .render (leftDiv);
130- contributors
131- .map (contributor => new Contributor (contributor))
132- .forEach (contributor => contributor .render (rightDiv));
133- });
134- })
135- .catch (error => {
136- // add error handling code here
137- });
144+ try {
145+ const contributors = await repo .fetchContributors ();
146+ repo .render (leftDiv);
147+ contributors
148+ .map (contributor => new Contributor (contributor))
149+ .forEach (contributor => contributor .render (contributorList));
150+ }
151+ catch (error) {
152+ createAndAppend (' div' , container, { html: error .message , class: ' alert alert-error' });
153+ }
138154 }
139155
140-
141156 /**
142157 * Fetch API data as JSON data in a promise
143158 * @param {string} url The URL of the API endpoint.
0 commit comments