Skip to content

Commit bded978

Browse files
committed
mv to jco dir, gitignore artifacts, use bindings dir for jco artifacts
1 parent fd88dd6 commit bded978

File tree

6 files changed

+26
-27
lines changed

6 files changed

+26
-27
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
**/.vscode
33
*.swp
44
*.swo
5+
6+
# Build artifacts from examples
7+
**/jco/bindings
8+
**/examples/**/*.wasm
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Wasm Component Calcultor in JavaScript
2+
3+
This is a `node` CLI and browesr based example implementation of running a component that exports the `calculate` interface from a JavaScript application. It uses [`jco`](https://bytecodealliance.github.io/jco/) to generate JavaScript bindings and shows how the same component can be executed in the browser or locally with Node. For another example of using `jco` with components in multiple environments, see the [`jco` example](https://github.com/bytecodealliance/jco/blob/main/docs/src/example.md).
4+
5+
```sh
6+
# Wasm refereced here was generated by cargo component.
7+
# See top-level README for commands to generate it.
8+
#
9+
# We want to *ommit* wasm requiring Wasi,
10+
# thus use `composed.wasm`, not the `command.wasm`.
11+
12+
# Transpile to generate bindings for JS:
13+
jco transpile ../composed.wasm -o bindings
14+
15+
# Serve required files (index.html & jco genereated files minimally):
16+
npx live-server .
17+
18+
# Run CLI example:
19+
node cli-calc.js
20+
```
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// See the README for details on *generation* of the required import
2-
import { calculate } from "./composed.js";
2+
import { calculate } from "./bindings/composed.js";
33

44
console.log("Answer (to life) = " + calculate.evalExpression("add", 21, 21));

component-model/examples/tutorial/www/index.html renamed to component-model/examples/tutorial/jco/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ <h1>Wasm Component Demo</h1>
1010
<p id="answer"></p>
1111

1212
<script type="module">
13-
import { calculate } from "./composed.js";
13+
import { calculate } from "./bindings/composed.js";
1414
function run() {
1515
var x = document.getElementById("lhs");
1616
var y = document.getElementById("rhs");

component-model/examples/tutorial/www/README.md

-25
This file was deleted.

0 commit comments

Comments
 (0)