import{_ as i,o as t,c as a,ae as e}from"./chunks/framework.C8AWLET_.js";const g=JSON.parse('{"title":"The Reactive Core: $( )","description":"","frontmatter":{},"headers":[],"relativePath":"api/$.md","filePath":"api/$.md"}'),n={name:"api/$.md"};function l(h,s,p,r,k,d){return t(),a("div",null,[...s[0]||(s[0]=[e(`

The Reactive Core: $( )

The $ function is the heart of SigPro. It is a Unified Reactive Constructor that handles state, derivations, and side effects through a single, consistent interface.

1. The Constructor: $( input )

Depending on what you pass into $( ), SigPro creates a different type of reactive primitive:

Input TypeResultInternal Behavior
Value (String, Number, Object...)SignalCreates a piece of mutable state.
FunctionComputed / EffectCreates a derived value that tracks dependencies.

2. Signal (State)

A Signal is a "box" that holds a value. It provides a getter/setter function to interact with that value.

Example:

javascript
const $name = $("Alice");

// Read the value (Getter)
console.log($name()); // "Alice"

// Update the value (Setter)
$name("Bob"); 

// Update based on previous value
$name(current => current + " Smith");

3. Computed (Derived State)

When you pass a function to $( ) that returns a value, SigPro creates a Computed Signal. It automatically tracks which signals are used inside it and re-runs only when they change.

Example:

javascript
const $price = $(100);
const $qty = $(2);

// Automatically tracks $price and $qty
const $total = $(() => $price() * $qty());

console.log($total()); // 200

$qty(3); // $total updates to 300 automatically

4. Effects (Side Effects)

An Effect is a function passed to $( ) that does not return a value (or returns undefined). SigPro treats this as a subscription that performs an action whenever its dependencies change.

Example:

javascript
const $theme = $("light");

// This effect runs every time $theme changes
$(() => {
  document.body.className = $theme();
  console.log("Theme updated to:", $theme());
});

$theme("dark"); // Logs: Theme updated to: dark

5. Summary Table: Usage Guide

PrimitiveLogic TypeReturns Value?Typical Use Case
SignalStaticYes (Mutable)const $user = $("Guest")
ComputedRead-onlyYes (Automatic)const $isLoggedIn = $(() => $user() !== "Guest")
EffectImperativeNo$(() => localStorage.setItem('user', $user()))

💡 Pro Tip: Naming Convention

In SigPro, we use the $ prefix (e.g., $count) for variables that hold a reactive function. This makes it easy to distinguish between a standard variable and a reactive one at a glance:

javascript
let count = 0;   // Static
const $count = $(0); // Reactive (Function)
`,30)])])}const c=i(n,[["render",l]]);export{g as __pageData,c as default};