@wasm-idle/vue
@wasm-idle/vue
Vue composables around the @wasm-idle/core playground binding. They accept plain values or refs,
recreate the binding when either input changes, and dispose it when the owning effect scope (for
example a component) is disposed.
This package contains no runtimes or UI. loadSandbox is any SandboxLoader from
@wasm-idle/core: (language) => Promise<Sandbox>.
pnpm add @wasm-idle/vue @wasm-idle/core vue
Peer dependencies: vue >= 3.4 and the matching @wasm-idle/core version.
Usage
<script setup lang="ts">
import { ref } from 'vue';
import { useWasmIdleHost } from '@wasm-idle/vue';
import { loadSandbox } from './sandboxes'; // your SandboxLoader
const props = defineProps<{ code: string }>();
const { binding } = useWasmIdleHost('https://cdn.example.com/wasm-idle', loadSandbox);
const output = ref('');
async function run() {
output.value = '';
const sandbox = await binding.value.load('PYTHON3');
sandbox.output = (chunk) => (output.value += chunk);
try {
await sandbox.load(props.code);
await sandbox.run(props.code, false);
} finally {
await sandbox.dispose?.();
}
}
</script>
<template>
<button @click="run">Run</button>
<pre>{{ output }}</pre>
</template>
API
useWasmIdlePlayground(runtimeAssets, loadSandbox)returns aRef<PlaygroundBinding>. Both arguments may be refs; when either value changes, a new binding is created and the previous one is disposed in the background.useWasmIdleHost(runtimeAssets, loadSandbox)returns thatbindingref plus aterminalshallow ref,setTerminal(), a computedterminalProps, anddispose().dispose()destroys the registered terminal and disposes the current binding, and rejects if either step fails (with anAggregateErrorwhen both fail).
When called inside an effect scope, both composables dispose their resources when the scope ends.
Outside a scope, call host.dispose() or binding.value.dispose() yourself.
runtimeAssets is a root URL string or a per-runtime configuration object. See the
wasm-idle repository for the runtime asset configuration and
the runtime execution and cleanup contract.
Version History
| Version | Released | License |
|---|---|---|
| 1.1.2 | MIT | |
| 1.1.0 | MIT | |
| 1.0.12 | MIT | |
| 1.0.11 | MIT | |
| 1.0.10 | MIT | |
| 1.0.9 | MIT | |
| 1.0.8 | MIT | |
| 1.0.7 | MIT | |
| 1.0.6 | MIT | |
| 1.0.5 | MIT | |
| 1.0.4 | MIT | |
| 1.0.3 | MIT | |
| 1.0.1 | MIT | |
| 1.0.0 | MIT |
Pre-releases (1)
| Version | Released | License |
|---|---|---|
| 1.0.0-next.0 | MIT |