import{_ as i,o as a,c as t,ae as n}from"./chunks/framework.C8AWLET_.js";const g=JSON.parse('{"title":"Extending SigPro: $.plugin","description":"","frontmatter":{},"headers":[],"relativePath":"plugins/quick.md","filePath":"plugins/quick.md"}'),e={name:"plugins/quick.md"};function l(h,s,p,k,r,o){return a(),t("div",null,[...s[0]||(s[0]=[n(`
$.plugin The plugin system is the engine's way of growing. It allows you to inject new functionality directly into the $ object or load external resources.
A plugin in SigPro is simply a function that receives the core instance. When you run $.plugin(MyPlugin), the engine hands over the $ object so the plugin can attach new methods or register global tags (like div(), span(), etc.).
// A plugin that adds a simple logger to any signal
const Logger = ($) => {
$.watch = (target, label = "Log") => {
$(() => console.log(\`[\${label}]:\`, target()));
};
};
// Activation
$.plugin(Logger);
const $count = $(0);
$.watch($count, "Counter"); // Now available globally via $Since plugins often set up global variables (like the HTML tags), the order of initialization is critical. Here are the two ways to start your app:
This is the most robust way. It ensures all global tags (div, button, etc.) are created before your App code is even read by the browser.
// main.js
import { $ } from 'sigpro';
import { UI, Router } from 'sigpro/plugins';
// 1. Load plugins first
$.plugin([UI, Router]).then(() => {
// 2. Import your app only after the environment is ready
import('./App.js').then(appFile => {
const MyApp = appFile.default;
$.mount(MyApp, '#app');
});
});Use this only if you prefer not to use global tags and want to use $.html directly in your components. This allows for standard static imports.
// main.js
import { $ } from 'sigpro';
import { UI } from 'sigpro/plugins';
import MyApp from './App.js'; // Static import works here
$.plugin(UI);
$.mount(MyApp, '#app');Warning: In this mode, if
App.jsusesdiv()instead of$.html('div'), it will throw aReferenceError.
You can pass a URL or an Array of URLs. SigPro will inject them as <script> tags and return a Promise that resolves when the scripts are fully loaded and executed.
// Loading external libraries as plugins
await $.plugin([
'https://cdn.jsdelivr.net/npm/chart.js',
'https://cdn.example.com/custom-ui-lib.js'
]);
console.log("External resources are ready to use!");The $.plugin method adapts to whatever you throw at it:
| Input Type | Action | Behavior |
|---|---|---|
| Function | Executes fn($) | Synchronous / Immediate |
| String (URL) | Injects <script src="..."> | Asynchronous (Returns Promise) |
| Array | Processes each item in the list | Returns Promise if any item is Async |
.then()? Using $.plugin([...]).then(...) is like giving your app a "Pre-flight Check". It guarantees that: