1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Use a module in a page
No install. The import map loads atlibs from jsdelivr, and `loadModule` fetches the module from its
publisher's PDS and checks it against the record.
Save as `index.html`:
```html run=network browser index.html
<!DOCTYPE html>
<meta charset="utf-8">
<script type="importmap">
{ "imports": { "atlibs/": "https://cdn.jsdelivr.net/npm/@publicdomainrelay/atlibs@0.5.0/src/" } }
</script>
<output></output>
<script type="module">
import { createPluginContext } from 'atlibs/plugin-context/index.js'
import { hostCall } from 'atlibs/run-module/host-call.js'
import { loadModule, runModule } from 'atlibs/run-module/index.js'
const did = 'did:plc:ocnuqjlzgohypj3zoznermms'
const ctx = createPluginContext({ id: 'demo' })
const hello = await loadModule(ctx, 'bobvmbuilder.bsky.social/hello')
const { result, error } = await runModule(ctx, hello, 'count', { did, collection: 'com.fedfork.exec.wasm.module' }, hostCall({ ctx }))
document.querySelector('output').textContent = JSON.stringify(error ?? result)
</script>
```
```output
{"collection":"com.fedfork.exec.wasm.module","records":…}
```
Serve it and open http://127.0.0.1:8000/:
```bash run=network
python3 -m http.server 8000 --bind 127.0.0.1 &
```
```bash run=network
curl -s localhost:8000/ | grep -c importmap
```
```output
1
```
Signed out, a module makes public reads only. Sign-in: [Sign in from a page](../browser/oauth.md). A
fuller page (components, a cubit, tests): `examples/web/hello`, [Run modules in a page](../browser/run-modules.md).
Next: [Node](node.md)