Skip to content

Commit

Permalink
Version 0.3.0
Browse files Browse the repository at this point in the history
PR-URL: #12
  • Loading branch information
tshemsedinov committed Aug 12, 2023
1 parent 37633ff commit 47715d3
Show file tree
Hide file tree
Showing 5 changed files with 1,115 additions and 355 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased][unreleased]

## [0.3.0][] - 2023-08-12

- Support in-place callbacks
- Avoid compiling WASM module twice in 'load' function

## [0.2.0][] - 2023-08-07
Expand All @@ -14,6 +17,7 @@

- Loader for node.js

[unreleased]: https://github.com/tshemsedinov/wasm-import/compare/v0.2.0...HEAD
[unreleased]: https://github.com/tshemsedinov/wasm-import/compare/v0.3.0...HEAD
[0.3.0]: https://github.com/tshemsedinov/wasm-import/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/tshemsedinov/wasm-import/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/tshemsedinov/wasm-import/releases/tag/v0.1.0
34 changes: 7 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,21 @@ https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Instan
```js
load(
fileName: string, // File name or URL
moduleName: string, // import key name in `importObject`
callbacks: Array<Function> // Array of callbacks to be imported im wasm
importObject?: object // See MDN docs
): Promise<object>;
```

## Example for Node.js

```js
const { load } = require('wasm-import');

const callback = (res) => {
console.log({ res });
};

(async () => {
const example = await load('./example.wasm', 'wbg', [callback]);
console.log({ sum });
example.instance.exports.add_callback(3, 7);
})();
```

## Example for Web
## Example

```js
import { load } from 'wasm-import';
// Alternative: const { load } = require('wasm-import');

const callback = (res) => {
console.log({ res });
};

const example = await load('./examples.wasm', 'wbg', [callback]);
const example = await load('example.wasm');

const sum = example.instance.exports.add(3, 7);
console.log({ sum });
example.instance.exports.add_callback(3, 7);
example.instance.exports.add(3, 7, (result) => {
console.log({ result, expected: 10 });
});
```

## License & Contributors
Expand Down
6 changes: 1 addition & 5 deletions loader.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
export function load(
fileName: string,
moduleName: string,
callbacks: Array<Function>,
): Promise<object>;
export function load(fileName: string, importObject?: object): Promise<object>;
Loading

0 comments on commit 47715d3

Please sign in to comment.