Skip to content
Verified

Xuda Slim

The lightweight browser entry point into the Xuda runtime, no project loader required.

Xuda Slim is the lightweight authoring and embedding surface for the Xuda runtime. It is useful when you want Xuda's reactive datasource, directives, events and structural tags, without starting from the full Xuda CLI project shape.

Slim is still Xuda, not a different runtime. Expressions still read fields with @field_name, the runtime still works from Xuda program documents, and structural tags such as xu-single-view and xu-panel still matter. <template> is supported, but it is not required.

What Slim is for

  • hand-authored HTML pages with Xuda reactivity
  • runtime demos and documentation
  • embeddable widgets or microsites
  • generated project_data runtime trees
  • progressive adoption of Xuda without introducing a full source compiler first

The three authoring modes

These modes can mix: if Slim receives project_data and the page also has <template> tags, the templates are parsed and added into project_data.programs alongside it.

Loading the runtime

The supported way to get the bundle is the public npm package @xuda.io/xuda-runtime-slim-es. If you have a deployed Xuda app, the platform also serves the runtime bundle from your own app domain at /cdn, with an unminified build at /cdn/debug.

html
<script src="https://xuda.ai/dist/runtime/js/xuda-runtime-slim.js"></script>
Don't load from a dev host in production

The script tag above points at a development host, useful for trying Slim locally. A deployed page should load @xuda.io/xuda-runtime-slim-es, or serve the bundle from your own app domain at /cdn.

The constructor

js
new xuda(element?, options?, callback?)
new xuda.xuda(element?, options?, callback?)

Arguments are matched by type, not position: an element, an options object and a callback can be passed in any order.

  • element: the DOM element to mount into. Optional in Slim: leave it out and the runtime falls back to document.body and logs a warning rather than failing.
  • options: session and runtime options, covered below.
  • callback: called as callback('xuda_ready', SESSION_ID, SESSION_OBJ) once the app is ready.

For mount completion, the most reliable hook is the on_mounted event on document.body:

js
document.body.addEventListener('on_mounted', () => {
  console.log('Slim page mounted');
}, { once: true });

Common options

Every option below resolves through the same six-step chain: a URL query parameter first, then an attribute on the root element, then options.params[key], then options[key], then a cookie, then localStorage. That is why a Slim page can be reconfigured from a query string with no code change.

How to know Slim is working

  • the bundle loaded
  • your prog_id renders something visible
  • the on_mounted event fires
  • field-driven UI updates begin to behave reactively

If all four happen, the page is in good shape. If nothing renders, check in order: the bundle actually loaded, prog_id matches a real template id or program key, the program exists in project_data.programs, and the mount target is a real element (or intentionally left to the body fallback).