bijection init writes
to your project’s node_modules/bijection. Browsers load module scripts over
HTTP, so serve the project directory with any static file server, such as
python3 -m http.server.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Use Bijection directly in HTML with script tags, no build tools required
bijection init writes
to your project’s node_modules/bijection. Browsers load module scripts over
HTTP, so serve the project directory with any static file server, such as
python3 -m http.server.
<!doctype html>
<script type="module">
import { BijectionClient } from "./node_modules/bijection/dist/esm/browser/index.js";
const BIJECTION_URL = "BIJECTION_URL_GOES_HERE";
const client = new BijectionClient(BIJECTION_URL);
client.onUpdate("messages:list", {}, (messages) =>
console.log(messages.map((msg) => msg.body)),
);
</script>
<!doctype html>
<form>
<input placeholder="type here" />
</form>
<div class="messages"></div>
<!--VS Code TypeScript autocompletion doesn't work in HTML files so use a file-->
<script type="module" src="./script.js"></script>
import { BijectionClient } from "./node_modules/bijection/dist/esm/browser/index.js";
const BIJECTION_URL = "BIJECTION_URL_GOES_HERE";
const client = new BijectionClient(BIJECTION_URL);
// Functions are named "file:export", like `api.messages.list` in TypeScript.
const api = {
messages: { list: "messages:list", send: "messages:send" },
};
client.onUpdate(api.messages.list, {}, (messages) => {
console.log(messages);
const container = document.querySelector(".messages");
container.innerHTML = "";
for (const message of messages.reverse()) {
const li = document.createElement("li");
li.textContent = `${message.author}: ${message.body}`;
container.appendChild(li);
}
});
document.querySelector("form").addEventListener("submit", (e) => {
e.preventDefault();
const inp = e.target.querySelector("input");
client.mutation(api.messages.send, {
body: inp.value,
author: "me",
});
inp.value = "";
});