Skip to content

Instantly share code, notes, and snippets.

@newbornfrontender
Last active November 2, 2018 09:18
Show Gist options
  • Save newbornfrontender/20cc0e82def057c767a227738bd990c0 to your computer and use it in GitHub Desktop.
Save newbornfrontender/20cc0e82def057c767a227738bd990c0 to your computer and use it in GitHub Desktop.
Lit-html (Promises)
<!doctype html>
<html dir="ltr" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Lit HTML</title>
</head>
<body>
<script type="module" src="/index.js"></script>
</body>
</html>
import { html, render } from './node_modules/lit-html/lit-html.js';
const printText = (introText, fileName) => html`
<p>
${introText}: ${fetch(`/${fileName}`).then(r => r.text())}
</p>
`;
render(printText('Promises in lit-html', 'index.txt'), document.body);
Promises are rendered when they resolve, leaving the previous value in place until they do. Races are handled, so that if an unresolved Promise is overwritten, it won’t update the template when it finally resolves
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment