Remove $.proxy
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* SigPro Core - Refactor Completo 2026
|
* SigPro Core
|
||||||
*/
|
*/
|
||||||
(() => {
|
(() => {
|
||||||
let activeEffect = null;
|
let activeEffect = null;
|
||||||
@@ -39,22 +39,6 @@
|
|||||||
if (!isFlushing) queueMicrotask(flush);
|
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) => {
|
const $ = (initial, key = null) => {
|
||||||
if (typeof initial === "function") {
|
if (typeof initial === "function") {
|
||||||
const subs = new Set();
|
const subs = new Set();
|
||||||
@@ -134,9 +118,6 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------
|
|
||||||
// --- $.effect = efectos ---
|
|
||||||
// -------------------------
|
|
||||||
$.effect = (fn) => {
|
$.effect = (fn) => {
|
||||||
const owner = currentOwner;
|
const owner = currentOwner;
|
||||||
|
|
||||||
@@ -185,41 +166,6 @@
|
|||||||
return effect.stop;
|
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) => {
|
const sweep = (node) => {
|
||||||
if (node._cleanups) {
|
if (node._cleanups) {
|
||||||
node._cleanups.forEach((f) => f());
|
node._cleanups.forEach((f) => f());
|
||||||
@@ -228,9 +174,6 @@
|
|||||||
node.childNodes?.forEach(sweep);
|
node.childNodes?.forEach(sweep);
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------
|
|
||||||
// --- Vistas reactivas ---
|
|
||||||
// -------------------------
|
|
||||||
$.view = (fn) => {
|
$.view = (fn) => {
|
||||||
const cleanups = new Set();
|
const cleanups = new Set();
|
||||||
const prev = currentOwner;
|
const prev = currentOwner;
|
||||||
@@ -262,9 +205,6 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------
|
|
||||||
// --- HTML con bindings ---
|
|
||||||
// -------------------------
|
|
||||||
$.html = (tag, props = {}, content = []) => {
|
$.html = (tag, props = {}, content = []) => {
|
||||||
if (props instanceof Node || Array.isArray(props) || typeof props !== "object") {
|
if (props instanceof Node || Array.isArray(props) || typeof props !== "object") {
|
||||||
content = props;
|
content = props;
|
||||||
@@ -341,9 +281,6 @@
|
|||||||
return el;
|
return el;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------
|
|
||||||
// --- Ignorar reactividad temporal ---
|
|
||||||
// -------------------------
|
|
||||||
$.ignore = (fn) => {
|
$.ignore = (fn) => {
|
||||||
const prev = activeEffect;
|
const prev = activeEffect;
|
||||||
activeEffect = null;
|
activeEffect = null;
|
||||||
@@ -354,9 +291,6 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------
|
|
||||||
// --- Router simple ---
|
|
||||||
// -------------------------
|
|
||||||
$.router = (routes) => {
|
$.router = (routes) => {
|
||||||
const sPath = $(window.location.hash.replace(/^#/, "") || "/");
|
const sPath = $(window.location.hash.replace(/^#/, "") || "/");
|
||||||
window.addEventListener("hashchange", () => 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(/^#?\/?/, "#/"));
|
$.router.go = (p) => (window.location.hash = p.replace(/^#?\/?/, "#/"));
|
||||||
|
|
||||||
// -------------------------
|
|
||||||
// --- Montaje de componentes ---
|
|
||||||
// -------------------------
|
|
||||||
$.mount = (component, target) => {
|
$.mount = (component, target) => {
|
||||||
const el = typeof target === "string" ? document.querySelector(target) : target;
|
const el = typeof target === "string" ? document.querySelector(target) : target;
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
@@ -414,9 +345,6 @@
|
|||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------
|
|
||||||
// --- Shortcuts para tags ---
|
|
||||||
// -------------------------
|
|
||||||
const 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(
|
`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+/,
|
/\s+/,
|
||||||
|
|||||||
Reference in New Issue
Block a user