Skip to content

Commit

Permalink
revert wasm loading
Browse files Browse the repository at this point in the history
  • Loading branch information
maxence-charriere committed Oct 18, 2021
1 parent 40f8cca commit ee17e24
Show file tree
Hide file tree
Showing 22 changed files with 1,700 additions and 1,756 deletions.
188 changes: 94 additions & 94 deletions docs/actions.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/app-worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const cacheName = "app-" + "8e0f1317d923632879808cfe869d42560fd3eecd";
const cacheName = "app-" + "49470db4017dfd3f09c7c0157e3ce83fc1201361";

self.addEventListener("install", event => {
console.log("installing app worker 8e0f1317d923632879808cfe869d42560fd3eecd");
console.log("installing app worker 49470db4017dfd3f09c7c0157e3ce83fc1201361");

event.waitUntil(
caches.open(cacheName).
Expand Down Expand Up @@ -44,7 +44,7 @@ self.addEventListener("activate", event => {
);
})
);
console.log("app worker 8e0f1317d923632879808cfe869d42560fd3eecd is activated");
console.log("app worker 49470db4017dfd3f09c7c0157e3ce83fc1201361 is activated");
});

self.addEventListener("fetch", event => {
Expand Down
76 changes: 24 additions & 52 deletions docs/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if ("serviceWorker" in navigator) {
// -----------------------------------------------------------------------------
// Env
// -----------------------------------------------------------------------------
const goappEnv = {"GOAPP_INTERNAL_URLS":"null","GOAPP_ROOT_PREFIX":"","GOAPP_STATIC_RESOURCES_URL":"","GOAPP_VERSION":"8e0f1317d923632879808cfe869d42560fd3eecd"};
const goappEnv = {"GOAPP_INTERNAL_URLS":"null","GOAPP_ROOT_PREFIX":"","GOAPP_STATIC_RESOURCES_URL":"","GOAPP_VERSION":"49470db4017dfd3f09c7c0157e3ce83fc1201361"};

function goappGetenv(k) {
return goappEnv[k];
Expand Down Expand Up @@ -95,60 +95,32 @@ function goappKeepBodyClean() {
// -----------------------------------------------------------------------------
// Init Web Assembly
// -----------------------------------------------------------------------------
async function initWebAssembly() {
if (!/bot|googlebot|crawler|spider|robot|crawling/i.test(navigator.userAgent)) {
const go = new Go();
if (!/bot|googlebot|crawler|spider|robot|crawling/i.test(navigator.userAgent)) {
if (!WebAssembly.instantiateStreaming) {
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}

const loaderLabel = document.getElementById("app-wasm-loader-label");
const go = new Go();

let response = await fetch("/web/app.wasm");
const reader = response.body.getReader();
const contentLength = response.headers.get('Content-Length');
WebAssembly.instantiateStreaming(fetch("/web/app.wasm"), go.importObject)
.then(result => {
const loaderIcon = document.getElementById("app-wasm-loader-icon");
loaderIcon.className = "goapp-logo";

let chunks = [];
let len = 0;
go.run(result.instance);
})
.catch(err => {
const loaderIcon = document.getElementById("app-wasm-loader-icon");
loaderIcon.className = "goapp-logo";

while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
const loaderLabel = document.getElementById("app-wasm-loader-label");
loaderLabel.innerText = err;

chunks.push(value);
len += value.length;
let progress = (len * 100 / contentLength).toFixed(2)
if (progress > 100) {
progress = (100).toFixed(2);
}
loaderLabel.innerText = progress + "%";
}

let wasmFile = new Uint8Array(len);
let idx = 0;
for (let c of chunks) {
wasmFile.set(c, idx);
idx += c.length;
}

WebAssembly.instantiate(wasmFile.buffer, go.importObject)
.then(result => {
const loaderIcon = document.getElementById("app-wasm-loader-icon");
loaderIcon.className = "goapp-logo";

go.run(result.instance);
})
.catch(err => {
const loaderIcon = document.getElementById("app-wasm-loader-icon");
loaderIcon.className = "goapp-logo";

const loaderLabel = document.getElementById("app-wasm-loader-label");
loaderLabel.innerText = err;

console.error("loading wasm failed: " + err);
});
} else {
document.getElementById('app-wasm-loader').style.display = "none";
}
console.error("loading wasm failed: " + err);
});
} else {
document.getElementById('app-wasm-loader').style.display = "none";
}

initWebAssembly();
176 changes: 88 additions & 88 deletions docs/architecture.html

Large diffs are not rendered by default.

180 changes: 90 additions & 90 deletions docs/components.html

Large diffs are not rendered by default.

162 changes: 81 additions & 81 deletions docs/concurrency.html

Large diffs are not rendered by default.

208 changes: 104 additions & 104 deletions docs/declarative-syntax.html

Large diffs are not rendered by default.

206 changes: 103 additions & 103 deletions docs/getting-started.html

Large diffs are not rendered by default.

162 changes: 81 additions & 81 deletions docs/github-deploy.html

Large diffs are not rendered by default.

206 changes: 103 additions & 103 deletions docs/index.html

Large diffs are not rendered by default.

198 changes: 99 additions & 99 deletions docs/install.html

Large diffs are not rendered by default.

184 changes: 92 additions & 92 deletions docs/js.html

Large diffs are not rendered by default.

180 changes: 90 additions & 90 deletions docs/lifecycle.html

Large diffs are not rendered by default.

172 changes: 86 additions & 86 deletions docs/migrate.html

Large diffs are not rendered by default.

172 changes: 86 additions & 86 deletions docs/privacy-policy.html

Large diffs are not rendered by default.

172 changes: 86 additions & 86 deletions docs/routing.html

Large diffs are not rendered by default.

164 changes: 82 additions & 82 deletions docs/seo.html

Large diffs are not rendered by default.

182 changes: 91 additions & 91 deletions docs/states.html

Large diffs are not rendered by default.

196 changes: 98 additions & 98 deletions docs/static-resources.html

Large diffs are not rendered by default.

190 changes: 95 additions & 95 deletions docs/testing.html

Large diffs are not rendered by default.

74 changes: 23 additions & 51 deletions pkg/app/gen/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,60 +95,32 @@ function goappKeepBodyClean() {
// -----------------------------------------------------------------------------
// Init Web Assembly
// -----------------------------------------------------------------------------
async function initWebAssembly() {
if (!/bot|googlebot|crawler|spider|robot|crawling/i.test(navigator.userAgent)) {
const go = new Go();
if (!/bot|googlebot|crawler|spider|robot|crawling/i.test(navigator.userAgent)) {
if (!WebAssembly.instantiateStreaming) {
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}

const loaderLabel = document.getElementById("app-wasm-loader-label");
const go = new Go();

let response = await fetch("{{.Wasm}}");
const reader = response.body.getReader();
const contentLength = response.headers.get('Content-Length');
WebAssembly.instantiateStreaming(fetch("{{.Wasm}}"), go.importObject)
.then(result => {
const loaderIcon = document.getElementById("app-wasm-loader-icon");
loaderIcon.className = "goapp-logo";

let chunks = [];
let len = 0;
go.run(result.instance);
})
.catch(err => {
const loaderIcon = document.getElementById("app-wasm-loader-icon");
loaderIcon.className = "goapp-logo";

while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
const loaderLabel = document.getElementById("app-wasm-loader-label");
loaderLabel.innerText = err;

chunks.push(value);
len += value.length;
let progress = (len * 100 / contentLength).toFixed(2)
if (progress > 100) {
progress = (100).toFixed(2);
}
loaderLabel.innerText = progress + "%";
}

let wasmFile = new Uint8Array(len);
let idx = 0;
for (let c of chunks) {
wasmFile.set(c, idx);
idx += c.length;
}

WebAssembly.instantiate(wasmFile.buffer, go.importObject)
.then(result => {
const loaderIcon = document.getElementById("app-wasm-loader-icon");
loaderIcon.className = "goapp-logo";

go.run(result.instance);
})
.catch(err => {
const loaderIcon = document.getElementById("app-wasm-loader-icon");
loaderIcon.className = "goapp-logo";

const loaderLabel = document.getElementById("app-wasm-loader-label");
loaderLabel.innerText = err;

console.error("loading wasm failed: " + err);
});
} else {
document.getElementById('app-wasm-loader').style.display = "none";
}
console.error("loading wasm failed: " + err);
});
} else {
document.getElementById('app-wasm-loader').style.display = "none";
}

initWebAssembly();
2 changes: 1 addition & 1 deletion pkg/app/scripts.go

Large diffs are not rendered by default.

0 comments on commit ee17e24

Please sign in to comment.