Sigment Guide

← Back to Home

Introduction

Sigment is a lightweight reactive framework designed for developers who want speed, simplicity,
and full control of the DOM without virtual DOM and transpilers.


sigment support spa architeture you can read about spa here

sigment also support html-first architecture with ssr or mixed ssr and client in same page
sigment use the mpa (Multi-Part Application) you can read about it here

πŸ“ Project Structure

Sigment keeps your project clean and organized. Here’s the recommended structure:

// Root directory
/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ assets/
β”‚   β”‚   └── css/
β”‚   β”‚       └── index.css
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   └── Hello.js
β”‚   └── Main.js
β”œβ”€β”€ index.html
β”œβ”€β”€ jsconfig.json
β”œβ”€β”€ vite.config.js
β”œβ”€β”€ global.d.ts
β”œβ”€β”€ package.json

πŸ”Ή src/ Directory

πŸ”Ή Root-Level Files

Example index.html

<!doctype html>
<html lang="en-US">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0">
    <title>sigment start</title>
    <link rel="stylesheet" href="/src/assets/css/index.css">
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/Main.js"></script>
  </body>
</html>

πŸš€ Main Entry Point

Your application starts from Main.js / ts. It imports your components and mounts them into the DOM using Sigment’s MyApp and mount() API.

import { MyApp, mount } from "sigment";
import Hello from "./components/Hello";

MyApp.cleanHtml(true);

function Main() {
  mount("root", Hello());
}

Main();

export default Main;

πŸ”Ž What’s Happening?

πŸš€ Hello component

Example of Hello component.

export default function Hello() {
  return div("Hello, world!");
}


rpc – Call Static Component Methods Remotely

The rpc function allows you to dynamically call static methods attached to a component, such as Dashboard.writeToLog, from outside the component context. This is useful for triggering logic or returning values from components programmatically.

Signature

function rpc(
  component,
  methods: Record<string, any[]>
): Record<string, any>;

Example 1 – call a void method

function Dashboard(props) {
  // component internals
}

Dashboard.writeToLog = function(from) {
  console.log("writeToLog is fired type is void", from);
};

rpc(Dashboard, {
  writeToLog: ["some text"]
});

This will run Dashboard.writeToLog("some text").

πŸ“¦ You can call this from another component like this dont forget to import Dashboard

rpc(Dashboard, {
  writeToLog: ["called from HomePage"]
});

Example 2 – call multiple methods with return values

Dashboard.writeToLogWithValue = function(val) {
  console.log("return value", val);
  return val;
};

const res = rpc(Dashboard, {
  writeToLog: ["some text"],
  writeToLogWithValue: ["i am with value"]
});

console.log(res);

Methods that return values will be included in the result. Methods returning undefined (like writeToLog) will appear with undefined in the response.

Note: Static methods like Dashboard.writeToLog must be defined outside the component’s render body. This ensures they’re available at any time and do not depend on component mounting.