Remove $.proxy

This commit is contained in:
2026-03-25 20:04:24 +01:00
parent fc9b58f51f
commit dc0dd202af

View File

@@ -1,5 +1,5 @@
/**
* SigPro Core - Refactor Completo 2026
* SigPro Core
*/
(() => {
let activeEffect = null;
@@ -39,22 +39,6 @@
if (!isFlushing) queueMicrotask(flush);
};
const isObj = (v) => v && typeof v === "object" && !(v instanceof Node);
const RAW_SUBS = new WeakMap();
const PROXIES = new WeakMap();
const getPropSubs = (target, prop) => {
let props = RAW_SUBS.get(target);
if (!props) RAW_SUBS.set(target, (props = new Map()));
let subs = props.get(prop);
if (!subs) props.set(prop, (subs = new Set()));
return subs;
};
// -------------------------
// --- $ = Signal puro + Persistencia ---
// -------------------------
const $ = (initial, key = null) => {
if (typeof initial === "function") {
const subs = new Set();
@@ -134,9 +118,6 @@
};
};
// -------------------------
// --- $.effect = efectos ---
// -------------------------
$.effect = (fn) => {
const owner = currentOwner;
@@ -185,41 +166,6 @@
return effect.stop;
};
// -------------------------
// --- $.proxy = Proxy profundo ---
// -------------------------
$.proxy = (obj) => {
if (!isObj(obj)) throw new Error("$.proxy only works with objects or arrays");
if (PROXIES.has(obj)) return PROXIES.get(obj);
const proxy = new Proxy(obj, {
get(t, p, r) {
track(getPropSubs(t, p));
const val = Reflect.get(t, p, r);
return val && typeof val === "object" ? $.proxy(val) : val;
},
set(t, p, v, r) {
const old = Reflect.get(t, p, r);
if (Object.is(old, v)) return true;
const res = Reflect.set(t, p, v, r);
trigger(getPropSubs(t, p));
if (Array.isArray(t) && p !== "length") trigger(getPropSubs(t, "length"));
return res;
},
deleteProperty(t, p) {
const res = Reflect.deleteProperty(t, p);
trigger(getPropSubs(t, p));
return res;
},
});
PROXIES.set(obj, proxy);
return proxy;
};
// -------------------------
// --- Sweep nodos y limpieza ---
// -------------------------
const sweep = (node) => {
if (node._cleanups) {
node._cleanups.forEach((f) => f());
@@ -228,9 +174,6 @@
node.childNodes?.forEach(sweep);
};
// -------------------------
// --- Vistas reactivas ---
// -------------------------
$.view = (fn) => {
const cleanups = new Set();
const prev = currentOwner;
@@ -262,9 +205,6 @@
};
};
// -------------------------
// --- HTML con bindings ---
// -------------------------
$.html = (tag, props = {}, content = []) => {
if (props instanceof Node || Array.isArray(props) || typeof props !== "object") {
content = props;
@@ -341,9 +281,6 @@
return el;
};
// -------------------------
// --- Ignorar reactividad temporal ---
// -------------------------
$.ignore = (fn) => {
const prev = activeEffect;
activeEffect = null;
@@ -354,9 +291,6 @@
}
};
// -------------------------
// --- Router simple ---
// -------------------------
$.router = (routes) => {
const sPath = $(window.location.hash.replace(/^#/, "") || "/");
window.addEventListener("hashchange", () => sPath(window.location.hash.replace(/^#/, "") || "/"));
@@ -401,9 +335,6 @@
$.router.go = (p) => (window.location.hash = p.replace(/^#?\/?/, "#/"));
// -------------------------
// --- Montaje de componentes ---
// -------------------------
$.mount = (component, target) => {
const el = typeof target === "string" ? document.querySelector(target) : target;
if (!el) return;
@@ -414,9 +345,6 @@
return instance;
};
// -------------------------
// --- Shortcuts para tags ---
// -------------------------
const tags =
`div span p h1 h2 h3 h4 h5 h6 br hr section article aside nav main header footer address ul ol li dl dt dd a em strong small i b u mark time sub sup pre code blockquote details summary dialog form label input textarea select button option fieldset legend table thead tbody tfoot tr th td caption img video audio canvas svg iframe picture source progress meter`.split(
/\s+/,