jac-cl-js-interop

Implements browser API interop patterns for client Jac code compiled to JavaScript.

Updated Jul 26, 2026
One-click install
npx skills add https://github.com/PMN123/trapdoor --skill jac-cl-js-interop-pmn123
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: jac-cl-js-interop
Source: https://github.com/PMN123/trapdoor/tree/main/.agents/skills/jac-cl-js-interop
Command: npx skills add https://github.com/PMN123/trapdoor --skill jac-cl-js-interop-pmn123

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Client Jac compiles to JavaScript, but key browser interop idioms differ from both Python and JS, causing parse errors, silent runtime crashes, and misleading compiler warnings when developers guess the syntax. ## Core Features & Use Cases - JS Constructor and Callback Idioms: Covers the new(Cls, ...) builtin for WebSocket, URL, Date, CustomEvent, and Promise, plus .call(None, ...) for invoking stored callbacks. - Module State and Browser Globals: Documents glob module-level state, localStorage, window/document access, timers, and JSON helpers available without imports. - Recipes and Gotchas: Provides WebSocket, CustomEvent bus, polling, debounce, and RAF patterns, plus fixes for chr(10) newline emission, let-scoping TDZ crashes, and is None versus undefined checks. - Use Case: When building a Jac client component that opens a WebSocket, dispatches cross-component events, or debounces input, load this Skill to write correct interop code and debug the compiled output in .jac/client/. ## Quick Start Load this Skill and show me how to connect a WebSocket in client Jac and handle incoming messages safely.

Frequently Asked Questions about jac-cl-js-interop

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a WebSocket in client Jac code?

Use the new() builtin: ws = new(WebSocket, url), since Jac has no JS-style new keyword and new WebSocket(url) is a parse error. Store the connection in a glob module variable and assign onopen, onmessage, and onclose lambdas.

How do I call a stored callback function in Jac?

Invoke stored callbacks with .call(None, args...) rather than calling the variable directly, because direct calls can miscompile for stored JS functions. This applies to Promise resolve/reject and any function stashed in a dict or variable.

Why does jac check flag WebSocket and window as undefined?

Isolated jac check has no typed stubs for browser globals, so it emits W2001 and related warnings on WebSocket, window, and JSON.parse. These patterns are correct at runtime and jac build succeeds; suppress per line with # jac:ignore[CODE] if needed.

Why does my Jac variable crash with ReferenceError after an if branch?

A variable first assigned inside an if/else body compiles to a block-scoped let, causing a TDZ ReferenceError when used after the branch. Give the variable its first assignment before the branch, for example with a conditional expression.

Does 'is None' catch undefined values in client Jac?

No. x is None compiles to strict x === null, so undefined values from missing dict keys or absent browser API results slip through. Guard with truthiness checks like if x { ... } whenever the value can come from a JS-shaped absence.