generated from Alorel/basic-library-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
186 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
export default function autoinitWasmImport(imp, url) { | ||
return Promise | ||
.all([ | ||
imp, | ||
fetch(url) | ||
]) | ||
.then(function wasmImportInitialiser([wasmModule, response]) { | ||
return wasmModule.default(response) | ||
.then(() => wasmModule); | ||
}); | ||
function createGetter(initResponse) { | ||
const getter = {}; | ||
Object.defineProperty(getter, '__getWasm', { | ||
value: function __getWasm() { | ||
return initResponse; | ||
} | ||
}); | ||
|
||
return getter; | ||
} | ||
|
||
/** | ||
* @param {Promise<any>} imp - The dynamic import | ||
* @param {string} url - The wasm file's URL | ||
* @param {boolean} exposeWasm - Whether to expose the init function's response or not | ||
*/ | ||
export default async function autoinitWasmImport(imp, url, exposeWasm) { | ||
const [wasmModule, fetchResponse] = await Promise.all([imp, fetch(url)]); | ||
const initResponse = await wasmModule.default(fetchResponse); | ||
|
||
return exposeWasm ? | ||
Object.assign(createGetter(initResponse), wasmModule) : | ||
wasmModule; | ||
} |
Oops, something went wrong.