This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Criando um nome para o arquivo de cache | |
const staticCache = "meu-site-2018-07-31-21-13"; | |
// Lista de arquivos que devem ser cacheados | |
const files = [ | |
'/', | |
'/sobre', | |
'/contato', | |
'/images/logo.jpg', | |
'/assets/styles/main.min.css', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
export default class UserData extends Component { | |
constructor(){ | |
super(); | |
this.state = { | |
name: '' | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reponde o request direto do cache | |
this.addEventListener("fetch", event => { | |
event.respondWith( | |
caches.match(event.request) | |
.then(response => { | |
// Retorna o cache | |
if (response) { | |
return response; | |
} | |
// Faz a requisição |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function useInput(initialValue = '') { | |
const [value, setValue] = useState(initialValue); | |
const onChange = e => setValue(e.target.value); | |
return { onChange, value } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function readTxtFile(event) { | |
return new Promise((resolve, reject) => { | |
const file = event.target.files[0]; | |
const reader = new FileReader(); | |
reader.onload = () => resolve(reader.result); | |
reader.readAsText(file); | |
}); | |
} |