Add worker support to examples

This commit is contained in:
Andreas Hocevar
2020-03-22 20:06:03 +01:00
parent 30ac91c4ae
commit bc1be50cbc
3 changed files with 59 additions and 16 deletions
+22 -14
View File
@@ -57,6 +57,8 @@
event.preventDefault();
const html = document.getElementById('example-html-source').innerText;
const js = document.getElementById('example-js-source').innerText;
const workerContainer = document.getElementById('example-worker-source');
const worker = workerContainer ? workerContainer.innerText : undefined;
const pkgJson = document.getElementById('example-pkg-source').innerText;
const form = document.getElementById('codepen-form');
@@ -68,22 +70,28 @@
Promise.all(promises)
.then(results => {
const data = {
files: {
'index.html': {
content: html
},
'index.js': {
content: js
},
"package.json": {
content: pkgJson
},
'sandbox.config.json': {
content: '{"template": "parcel"}'
}
const files = {
'index.html': {
content: html
},
'index.js': {
content: js
},
"package.json": {
content: pkgJson
},
'sandbox.config.json': {
content: '{"template": "parcel"}'
}
};
if (worker) {
files['worker.js'] = {
content: worker
}
}
const data = {
files: files
};
for (let i = 0; i < localResources.length; i++) {
data.files[localResources[i]] = results[i];