Przejdź do treści
Zweryfikowano

Tworzenie w project_data

Zbuduj drzewo uruchomieniowe Xuda jawnie jako dane, dla generatora lub wyniku deterministycznego.

Slim można też tworzyć z jawnego JSON-a uruchomieniowego. W tym trybie Twój kod buduje ten sam kształt programu, który środowisko Xuda już przyjmuje. Przydaje się, gdy drzewem UI zarządza inny system albo strona ma być generowana deterministycznie.

Zamiast pisać:

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

budujesz drzewo węzłów bezpośrednio:

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: [],
            },
          ],
        },
      ],
    },
  },
};

Montowanie

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 });

Kształt

Kiedy tworzenie w JSON pasuje lepiej

Używaj go, gdy program generuje kreator lub narzędzie kodu, chcesz dokładnej kontroli nad identyfikatorami węzłów i strukturą albo uczysz się samego kształtu środowiska. To też najszybszy sposób, by zrozumieć, co kompilator CLI emituje za kulisami: pliki .xu ostatecznie kompilują się do tego samego modelu dokumentu.