Lever-age / frontend

Leverage user facing frontend
GNU Affero General Public License v3.0
1 stars 6 forks source link

Add utility methods to render templates and fill containers #80

Closed lottspot closed 7 years ago

lottspot commented 7 years ago

This pull would allow candidate-detail.js to be simplified in the following way, by offloading more work into core.js:

diff --git a/src/js/candidate-detail.js b/src/js/candidate-detail.js
index 378dc71..c492a50 100644
--- a/src/js/candidate-detail.js
+++ b/src/js/candidate-detail.js
@@ -1,5 +1,4 @@

-let html = document.getElementById('mustache-template').innerHTML;
 let htmlContainer = 'pageContent';

 module.exports = (core) => {
@@ -10,8 +9,7 @@ module.exports = (core) => {

     candidate.data[0].name_full = `${candidate.data[0].name_first}  ${candidate.data[0].name_last}`;

-    let output = core.Mustache.render(html, { candidate: candidate.data[0] });
-    document.getElementById(htmlContainer).innerHTML = output;
-    document.title = candidate.data[0].name_full;
+    let nodes = core.renderTemplate('mustache-template', { candidate: candidate.data[0] });
+    core.fillContainer(htmlContainer, nodes);
   }).catch((err) => core.handleError(err, htmlContainer));
 };