UNPKG

1.41 kBJavaScriptView Raw
1import { h } from '@stencil/core';
2export class AsyncContent {
3 constructor() {
4 this.content = '';
5 }
6 componentWillLoad() {
7 if (this.documentLocation != null) {
8 return this.fetchNewContent(this.documentLocation);
9 }
10 }
11 fetchNewContent(newDocumentLocation) {
12 return fetch(newDocumentLocation)
13 .then(response => response.text())
14 .then(data => {
15 this.content = data;
16 });
17 }
18 render() {
19 return (h("div", { innerHTML: this.content }));
20 }
21 static get is() { return "stencil-async-content"; }
22 static get properties() { return {
23 "documentLocation": {
24 "type": "string",
25 "mutable": false,
26 "complexType": {
27 "original": "string",
28 "resolved": "string | undefined",
29 "references": {}
30 },
31 "required": false,
32 "optional": true,
33 "docs": {
34 "tags": [],
35 "text": ""
36 },
37 "attribute": "document-location",
38 "reflect": false
39 }
40 }; }
41 static get states() { return {
42 "content": {}
43 }; }
44 static get watchers() { return [{
45 "propName": "documentLocation",
46 "methodName": "fetchNewContent"
47 }]; }
48}