Fix and nits
This commit is contained in:
Родитель
5cb8ef221a
Коммит
116834ca0f
|
@ -36,13 +36,10 @@ function loadPokemonList() {
|
|||
// by the service worker.
|
||||
function fillPokemonList(pokemonList) {
|
||||
var listElement = document.getElementById('pokemon-list');
|
||||
var total = pokemonList.length;
|
||||
var buffer = [];
|
||||
for (var index = 0; index < total; index++) {
|
||||
var pokemon = pokemonList[index];
|
||||
var buffer = pokemonList.map(function(pokemon) {
|
||||
var uriTokens = pokemon.resource_uri.split('/');
|
||||
var id = uriTokens[uriTokens.length - 2];
|
||||
buffer.push('<li><a href="pokemon.html?id=' + id + '">' + pokemon.name + '</a></li>');
|
||||
}
|
||||
return '<li><a href="pokemon.html?id=' + id + '">' + pokemon.name + '</a></li>';
|
||||
});
|
||||
listElement.innerHTML = buffer.join('\n');
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ var interpolationTime = 0;
|
|||
var fetchingModelTime = 0;
|
||||
|
||||
// Here is the idea. This is the template for a Pokemon. It is
|
||||
// in charge of parse which Pokemon is requested from the querystring
|
||||
// in charge of parsing which Pokemon is requested from the querystring
|
||||
// of the URL, fetch that pokemon and fill the template. Once the template
|
||||
// has been filled, we are going to mark the document as cached and send
|
||||
// to the render-store by sending the contents to the service worker.
|
||||
|
@ -41,6 +41,13 @@ function getPokemon(id) {
|
|||
function fillCharSheet(pokemon) {
|
||||
var element = document.querySelector('body');
|
||||
element.innerHTML = interpolateTemplate(element.innerHTML, pokemon);
|
||||
|
||||
// Specifically for the cookbook site :(
|
||||
document.querySelector('img').onload = function() {
|
||||
if (window.parent !== window) {
|
||||
window.parent.document.body.dispatchEvent(new CustomEvent('iframeresize'));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Log times for interpolation, fetching and total loading times.
|
||||
|
|
|
@ -17,9 +17,11 @@ self.onfetch = function(event) {
|
|||
// For this example, `GET` implies looking for a cached copy...
|
||||
if (event.request.method === 'GET') {
|
||||
event.respondWith(getFromRenderStoreOrNetwork(event.request));
|
||||
// While `PUT` means to cache contents...
|
||||
} else {
|
||||
event.respondWith(cacheInRenderStore(event.request).then(createdResponse));
|
||||
// While `PUT` means to cache contents...
|
||||
event.respondWith(cacheInRenderStore(event.request).then(function() {
|
||||
return new Response({ status: 202 });
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -38,7 +40,7 @@ function getFromRenderStoreOrNetwork(request) {
|
|||
// result.
|
||||
function cacheInRenderStore(request) {
|
||||
return request.text().then(function(contents) {
|
||||
// Craft a `tesxt/html` response for the contents to be cached.
|
||||
// Craft a `text/html` response for the contents to be cached.
|
||||
var headers = { 'Content-Type': 'text/html' };
|
||||
var response = new Response(contents, { headers: headers });
|
||||
return self.caches.open('render-store').then(function(cache) {
|
||||
|
@ -50,8 +52,3 @@ function cacheInRenderStore(request) {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Return a 202 response.
|
||||
function createdResponse() {
|
||||
return new Response({ status: 202 });
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче