https://github.com/kwonoj/emscripten-wasm-loader
https://github.com/kwonoj/emscripten-wasm-loader
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/kwonoj/emscripten-wasm-loader
- Owner: kwonoj
- Created: 2017-09-14T00:33:57.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-02-11T19:07:56.000Z (over 4 years ago)
- Last Synced: 2024-10-19T18:30:02.440Z (almost 2 years ago)
- Language: TypeScript
- Size: 711 KB
- Stars: 9
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
[](https://travis-ci.org/kwonoj/emscripten-wasm-loader)
[](https://ci.appveyor.com/project/kwonoj/emscripten-wasm-loader/branch/master)
[](https://codecov.io/gh/kwonoj/emscripten-wasm-loader)
[](https://www.npmjs.com/package/emscripten-wasm-loader)
# Emscripten-wasm-loader
Wraps up common initialization logic with predefined preprocessor object. This module intended to support specific scoped usecase for wasm binary built with `MODULARIZED` and `SINGLE_FILE`.
# Usage
```js
import { getModuleLoader } from 'emscripten-wasm-loader';
const loader = getModuleLoader(factoryLoader, require('wasm/wasmlibaray'), { additional: ''});
```
`getModuleLoader` is higher order function returns actual module loader.
```js
getModuleLoader(
factoryLoader: (runtime: R) => T,
runtimeModule: runtimeModuleType,
module?: Record
) => moduleLoaderType;
/**
* Asynchronously load and initialize asm module.
*
* @returns {T} Factory function manages lifecycle of hunspell and virtual files.
*/
type moduleLoaderType = () => Promise;
```
`factoryLoader` is callback function to be called to create actual instance of module using initialized wasm binary runtime for customized init steps for each consumer. `runtimeModule` is function loaded via `require` to emscripten preamble js for wasm binaries. It expects wasm binary should be built with `MODULARIZE=1` with `SINGLE_FILE=1` option. Lastly `module` is object to be inherited when execute `runtimeModule`. Emscripten's modularized preamble construct scoped wasm runtime module named `Module`, allows to have predefined object if needed. Internally `getModuleLoader` augments given object and set default interfaces like `initializeRuntime`.