Skip to content
This repository has been archived by the owner on Jun 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #17 from diox/unbreak-views-in-prod
Browse files Browse the repository at this point in the history
Resolve install promise immediately if we already indexed (bug 995246)
  • Loading branch information
diox committed Apr 14, 2014
2 parents 9e798c6 + 1e9aedf commit 58ce2d2
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 25 deletions.
28 changes: 24 additions & 4 deletions src/media/js/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@ define('install',
['apps', 'dom', 'indexing', 'log', 'notification', 'pages', 'settings', 'storage', 'templating', 'url', 'utils'],
function(apps, $, indexing, log, notification, pages, settings, storage, templating, url, utils) {
var docs = {}; // Holds the apps.
var indexed = indexing.index();
var indexed = false;
var gettext = templating._l;
var queuedInstalls = JSON.parse(storage.getItem('queuedInstalls') || '[]');

function getDocs() {
return docs;
}

function hideSplash() {
// FIXME: move elsewhere.
// We're ready to rumble. Remove splash screen!
console.log('Preparing to remove slash screen...');
document.body.removeChild(document.getElementById('splash-overlay'));
console.log('Hiding splash screen (' + ((window.performance.now() - window.start_time) / 1000).toFixed(6) + 's)');
}

var installApp = function(app) {
return new Promise(function(resolve, reject) {
console.log('Installing ' + app.name + ': ' + app.manifest_url);
Expand Down Expand Up @@ -129,7 +137,14 @@ define('install',

var init = function() {
return new Promise(function(resolve, reject) {
indexed.then(function(data) {
console.log('Waiting for indexed Promise...');
if (indexed === true) {
console.log('Already indexed, resolving install Promise directly');
resolve(docs);
return;
}
indexing.index().then(function(data) {
console.log('indexed Promise done...');
// Populate list of docs.
docs = data;

Expand All @@ -148,7 +163,11 @@ define('install',
});
});

resolve();
// Mark as indexed so that we don't wait for the index Promise next time.
indexed = true;

console.log('Resolving install Promise...');
resolve(docs);
});
});
};
Expand All @@ -158,5 +177,6 @@ define('install',
init: init,
installApp: installApp,
installQueuedInstalls: installQueuedInstalls,
hideSplash: hideSplash
};
});
});
2 changes: 1 addition & 1 deletion src/media/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ define('main', [], function () {
});

$.delegate('keypress', 'body:not(.results) input[name=q]', function() {
app.load('/');
app.load('/search/');
});

templating.render('header', function(res) {
Expand Down
8 changes: 4 additions & 4 deletions src/media/js/views/category.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
define('views/category',
['categories', 'dom', 'indexing', 'log', 'templating'],
function(categories, $, indexing, log, templating) {
['categories', 'dom', 'install', 'log', 'templating'],
function(categories, $, install, log, templating) {

// var console = log('views/category');
var docs = [];
var indexed = indexing.index();

function init(params) {
console.log('Initializing category view: ' + params.slug);
Expand All @@ -17,7 +16,7 @@ define('views/category',
return;
}

indexed.then(function(data) {
install.init().then(function(data) {

docs = data;
document.body.className = 'category';
Expand Down Expand Up @@ -53,6 +52,7 @@ define('views/category',
$('main ol').innerHTML = res;
});
});
install.hideSplash();
}

return {
Expand Down
8 changes: 4 additions & 4 deletions src/media/js/views/detail.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
define('views/detail',
['apps', 'content-ratings', 'cache', 'dom', 'indexing', 'log', 'notification', 'pages', 'settings', 'storage', 'templating', 'url', 'utils'],
function(apps, Cache, iarc, $, indexing, log, notification, pages, settings, storage, templating, url, utils) {
['apps', 'content-ratings', 'cache', 'dom', 'install', 'log', 'notification', 'pages', 'settings', 'storage', 'templating', 'url', 'utils'],
function(apps, Cache, iarc, $, install, log, notification, pages, settings, storage, templating, url, utils) {

var console = log('detail');
var indexed = indexing.index();
var doc;
var activeThumbnail = 0;

Expand Down Expand Up @@ -31,12 +30,13 @@ define('views/detail',
// Bail if we've already rendered this page.
return;
}
indexed.then(function(data) {
install.init().then(function(data) {
doc = find(data, params.slug);
// FIXME: error if not found
document.body.className = 'detail';
document.body.dataset.page = 'detail-' + doc.slug;
details();
install.hideSplash();
});
}

Expand Down
14 changes: 6 additions & 8 deletions src/media/js/views/featured.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
define('views/featured',
['dom', 'indexing', 'log', 'templating'],
function($, indexing, log, templating) {
['dom', 'install', 'log', 'templating'],
function($, install, log, templating) {

var console = log('views/featured');
var docs = [];
var featured = [];
var indexed = indexing.index();

function init(params) {
console.log('Initializing featured view');
Expand All @@ -16,12 +15,11 @@ define('views/featured',
return;
}

indexed.then(function(data) {

console.log('Waiting for install Promise...');
install.init().then(function(data) {
docs = data;
document.body.className = page_name;
document.body.dataset.page = page_name;
timeStart = window.performance.now();

// This will eventually be replaced by real logic.
Object.keys(docs).forEach(function(key) {
Expand All @@ -32,7 +30,7 @@ define('views/featured',

// Render the document
render(featured);

install.hideSplash();
});

}
Expand All @@ -49,7 +47,7 @@ define('views/featured',
});
templating.render('results', {data: data, docs: null}, function(res) {
$('main ol').innerHTML = res;
console.log('Finished rendering featured view.')
console.log('Finished rendering featured view.');
});
});
}
Expand Down
4 changes: 1 addition & 3 deletions src/media/js/views/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ define('views/search',
$('main').innerHTML = res;
console.log('Done rendering browse template, now waiting for indexed promise...');
install.init().then(function() {
// We're ready to rumble. Remove splash screen!
document.body.removeChild(document.getElementById('splash-overlay'));
console.log('Hiding splash screen (' + ((window.performance.now() - window.start_time) / 1000).toFixed(6) + 's)');

// Initialize and then render search template.
document.body.className = 'results';
Expand All @@ -42,6 +39,7 @@ define('views/search',
q.value = GET.q;
}
search();
install.hideSplash();

});
});
Expand Down
2 changes: 1 addition & 1 deletion src/templates/header.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form action="/">
<form action="/search/">
<h1><a class="logo" href="/">Firefox Marketplace</a></h1>
<input type="search" name="q" title="" x-inputmode="verbatim" autocapitalize="off" autocomplete="off" autocorrect="off" required placeholder="{{ _('Search', 'search') }}">
<a class="search-clear"></span>
Expand Down

0 comments on commit 58ce2d2

Please sign in to comment.