import{_ as i,o as a,c as t,ae as e}from"./chunks/framework.C8AWLET_.js";const c=JSON.parse('{"title":"🔌 Application Mounter: $.mount( )","description":"","frontmatter":{},"headers":[],"relativePath":"api/mount.md","filePath":"api/mount.md"}'),n={name:"api/mount.md"};function l(h,s,p,o,r,k){return a(),t("div",null,[...s[0]||(s[0]=[e(`
$.mount( ) ​The $.mount function is the entry point of your reactive world. It bridges the gap between your SigPro logic and the browser's Real DOM by injecting a component into the document.
$.mount(node: Function | HTMLElement, target?: string | HTMLElement): RuntimeObject| Parameter | Type | Default | Description |
|---|---|---|---|
node | Function or Node | Required | The component function or DOM element to render. |
target | string or Node | document.body | CSS selector or DOM element where the app will live. |
Returns: A Runtime object containing the container and a destroy() method.
In a modern Single Page Application, you typically want SigPro to manage the entire view. By default, if no target is provided, it mounts to document.body.
import { $ } from './sigpro.js';
import App from './App.js';
// Mounts your main App component directly to the body
$.mount(App);If your HTML has a predefined structure, you can tell SigPro exactly where to render by passing a CSS selector or a direct reference.
<div id="sidebar"></div>
<main id="app-root"></main>// Mount using a CSS selector
$.mount(MyComponent, '#app-root');
// Mount using a direct DOM reference
const sidebar = document.querySelector('#sidebar');
$.mount(SidebarComponent, sidebar);SigPro is excellent for "sprinkling" reactivity onto legacy or static pages. You can inject small reactive widgets into any part of an existing HTML layout.
// A small reactive widget
const CounterWidget = () => {
const count = $(0);
return Button({ onclick: () => count(c => c + 1) }, [
"Clicks: ", count
]);
};
// Mount it into a specific div in your static HTML
$.mount(CounterWidget, '#counter-container');When $.mount is executed, it performs these critical steps:
$.view(). This starts tracking all internal signals and effects.target.replaceChildren(). This efficiently wipes any existing HTML or "zombie" nodes inside the target before mounting.Runtime instance associated with that DOM element. If you call $.mount again on the same target, SigPro automatically destroys the previous app to prevent memory leaks.By importing your core in your entry file, SigPro automatically initializes global Tag Constructors (Div, Span, H1, etc.). This allows for a clean, declarative DX across your entire project.
// main.js
import './sigpro.js';
// Now any file can simply do:
$.mount(() => H1("Global SigPro App"));If you prefer to avoid global variables, you can use the low-level $.html factory to create elements locally.
import { $ } from './sigpro.js';
const myNode = $.html('div', { class: 'widget' }, 'Local Instance');
$.mount(myNode, '#widget-target');| Goal | Code Pattern |
|---|---|
| Mount to body | $.mount(App) |
| Mount to ID | $.mount(App, '#root') |
| Mount to Element | $.mount(App, myElement) |
| Mount raw Node | $.mount(Div("Hello"), '#id') |
| Unmount/Destroy | const app = $.mount(App); app.destroy(); |