Skip to content
Verified

project_data authoring

Build the Xuda runtime tree explicitly as data, for a generator or deterministic output.

Slim can also be authored from explicit runtime JSON. In this mode your code builds the same program shape the Xuda runtime already consumes, useful when another system owns the UI tree or the page should be generated deterministically.

Instead of writing:

html
<div xu-store="{'count':0}">
  <button xu-click="{'@count': @count + 1}">Increment</button>
</div>

you build the node tree directly:

js
export const project_data = {
  globals: {
    ViewEventObj: {},
    progFields: [],
    properties: { menuType: 'globals' },
  },
  tables: {},
  programs: {
    hello: {
      _id: 'hello',
      properties: { menuType: 'component', renderType: 'form' },
      progDataSource: {},
      progEvents: [],
      progFields: [],
      progUi: [
        {
          id: 'root',
          type: 'element',
          tagName: 'xu-single-view',
          attributes: {},
          children: [
            {
              id: 'button_1',
              type: 'element',
              tagName: 'button',
              attributes: {
                'xu-content': 'Increment',
                'xu-click': "{'@count': @count + 1}",
              },
              children: [],
            },
          ],
        },
      ],
    },
  },
};

Mounting it

js
import { xuda as xudaRuntime } from '@xuda.io/xuda-runtime-slim-es';
import { project_data } from './project_data.js';

const Xuda = xudaRuntime.xuda || xudaRuntime.default || xudaRuntime;

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

  new Xuda(document.body, { domain: 'xuda.ai', prog_id: 'hello', project_data });
}, { once: true });

The shape

When JSON authoring is the better fit

Use it when a builder or code tool generates the program, you want exact control over node ids and structure, or you are teaching the runtime shape itself. It is also the fastest way to understand what the CLI's compiler emits behind the scenes: .xu files ultimately compile to this same document model.