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,r,o,k){return a(),t("div",null,[...s[0]||(s[0]=[n(`
$.plugin The plugin system is the engine's modular backbone. It allows you to inject new functionality directly into the $ object, register custom global tags, or load external libraries seamlessly.
A plugin in SigPro is a function that receives the core instance. When you call $.plugin(MyPlugin), the engine hands over the $ object so the plugin can attach new methods or extend the reactive system.
// A plugin that adds a simple watcher 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 $Thanks to the Synchronous Tag Engine, you no longer need complex import() nesting. Global tags like div(), span(), and button() are ready the moment you import the Core.
This is the standard way to build apps. It's clean, readable, and supports standard ESM imports.
// main.js
import { $ } from 'sigpro';
import { Fetch } from 'sigpro/plugins';
import App from './App.js'; // Static import works perfectly!
// 1. Register plugins
$.plugin(Fetch);
// 2. Mount your app directly
$.mount(App, '#app');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. This is perfect for integrating heavy third-party libraries only when needed.
// Loading external libraries as plugins
$.plugin([
'https://cdn.jsdelivr.net/npm/chart.js',
'https://cdn.example.com/custom-ui-lib.js'
]).then(() => {
console.log("External resources are ready to use!");
$.mount(DashboardApp);
});The $.plugin method is smart; it adapts its behavior based on the input type:
| Input Type | Action | Behavior |
|---|---|---|
| Function | Executes fn($) | Synchronous: Immediate availability. |
| String (URL) | Injects <script src="..."> | Asynchronous: Returns a Promise. |
| Array | Processes each item in the list | Returns a Promise if any item is a URL. |
.then()? In SigPro, you only need .then() in two specific cases:
App.js requires a variable that is strictly defined inside an asynchronous external script (like window.Chart).For everything else (UI components, Router, Local State), just call $.plugin() and continue with your code. It's that simple.
| Goal | Code |
|---|---|
| Local Plugin | $.plugin(myPlugin) |
| Multiple Plugins | $.plugin([UI, Router]) |
| External Library | $.plugin('https://...').then(...) |
| Hybrid Load | $.plugin([UI, 'https://...']).then(...) |