Skip to content

Commit 1fb7435

Browse files
authored
Merge pull request #1 from mozilla-iot/async
Load view asynchronously when extension is loaded.
2 parents aedacdf + b562716 commit 1fb7435

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

js/extension.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
constructor() {
44
super('example-extension');
55
this.element = this.addMenuEntry('Example Extension');
6+
this.content = '';
7+
8+
fetch(`/extensions/${this.id}/views/content.html`)
9+
.then((res) => res.text())
10+
.then((text) => this.content = text)
11+
.catch((e) => console.error('Failed to fetch content:', e));
612
}
713

814
show() {
9-
const content = `<div id="extension-example-extension-content">
10-
<h1>Hello, world!</h1>
11-
</div>`;
12-
13-
this.element.innerHTML = content;
15+
this.element.innerHTML = this.content;
1416
}
1517
}
1618

manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"web_accessible_resources": [
2929
"css/*.css",
3030
"images/*.svg",
31-
"js/*.js"
31+
"js/*.js",
32+
"views/*.html"
3233
]
3334
}

views/content.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div id="extension-example-extension-content">
2+
<h1>Hello, world!</h1>
3+
</div>

0 commit comments

Comments
 (0)