콘텐츠로 이동

zwire-wasm (Bridge)

이 콘텐츠는 아직 번역되지 않았습니다.

Expose an existing Rust zwire::core::Scope to JavaScript through wasm-bindgen. The bridge sends the same committed JSON snapshots and transaction batches as the native protocol. Each connection owns its own transaction history and FIFO. The optional crate builds independently from the dependency-free Rust workspace.

Return a WireScope from your wasm-bindgen domain object:

pub fn connect(&self, peer: String) -> zwire_wasm::WireScope {
zwire_wasm::WireScope::connect(&self.scope, peer)
}

Connect it to the frontend after initializing the generated WASM module:

import { createScope } from '@zwire/core';
import { connectWasm } from '@zwire/core/protocol/wasm';
const scope = createScope();
const peer = engine.connect(crypto.randomUUID());
const connection = connectWasm(scope, peer);
engine.updateMarket();
connection.pull();
connection.dispose();
peer.free();
scope.dispose();

Use one WireScope per frontend connection. Local committed writes reach Rust synchronously. Call pull() after Rust commands to deliver their commits to JS, including commits produced by Rust subscribers. Dispose the connection before freeing the peer. The order book example runs this lifecycle with a React UI.