From a920adf59a0954476cf21644ba2a6ae59f3c5ee3 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Fri, 4 Oct 2019 10:05:37 -0300 Subject: [PATCH] wrap the pre-existing setup in a promise to confirm we can asynchronously setup the site --- javascripts/main.js | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/javascripts/main.js b/javascripts/main.js index cb411b832a9a..49d97b3ac084 100644 --- a/javascripts/main.js +++ b/javascripts/main.js @@ -289,27 +289,35 @@ define([ window.location.href = '#/tags/' + tagsString; }); - var projectsSvc = new ProjectsService(projects); - - var app = sammy(function() { - /* - * This is the route used to filter by tags/names/labels - * It ensures to read values from the URI query param and perform actions - * based on that. NOTE: It has major side effects on the browser. - */ - this.get('#/filters', function() { - var labels = prepareForHTML(getParameterByName('labels')); - var names = prepareForHTML(getParameterByName('names')); - var tags = prepareForHTML(getParameterByName('tags')); - renderProjects(projectsSvc, tags, names, labels); + function promiseWrappedProjects() { + return new Promise(function(resolve) { + resolve(projects); }); + } + + promiseWrappedProjects().then(function(p) { + var projectsSvc = new ProjectsService(p); + + var app = sammy(function() { + /* + * This is the route used to filter by tags/names/labels + * It ensures to read values from the URI query param and perform actions + * based on that. NOTE: It has major side effects on the browser. + */ + this.get('#/filters', function() { + var labels = prepareForHTML(getParameterByName('labels')); + var names = prepareForHTML(getParameterByName('names')); + var tags = prepareForHTML(getParameterByName('tags')); + renderProjects(projectsSvc, tags, names, labels); + }); - this.get('#/', function() { - renderProjects(projectsSvc); + this.get('#/', function() { + renderProjects(projectsSvc); + }); }); - }); - app.raise_errors = true; - app.run('#/'); + app.raise_errors = true; + app.run('#/'); + }); }); });