libreria-renderizado-npm
Version:
Una librería básica para gestionar el estado y JSX
2 lines (1 loc) • 1.35 kB
JavaScript
(function(o,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(o=typeof globalThis<"u"?globalThis:o||self,s(o.MiLibreriaReactiva={}))})(this,function(o){"use strict";function s(r){let t=r;const i=new Set;function n(f){f!==t&&(t=f,i.forEach(c=>c()))}function e(){return t}function u(f){if(typeof f!="function")throw new Error("El listener debe ser una función");return i.add(f),()=>i.delete(f)}return[e,n,u]}function d(r,t,...i){if(typeof r!="string")throw new Error("El tipo del elemento debe ser una cadena");const n=document.createElement(r);return t&&Object.keys(t).forEach(e=>{if(e.startsWith("on")){const u=e.substring(2).toLowerCase();typeof t[e]=="function"?n.addEventListener(u,t[e]):console.warn(`El manejador del evento ${u} no es una función.`)}else e==="className"?n.classList.add(t[e]):n.setAttribute(e,t[e])}),i.forEach(e=>{typeof e=="string"?n.appendChild(document.createTextNode(e)):e instanceof HTMLElement&&n.appendChild(e)}),n}function a(r,t){if(!t||!(t instanceof HTMLElement))throw new Error("El contenedor debe ser un elemento DOM válido");function i(){const{element:e}=r();t.innerHTML="",t.appendChild(e)}i();const n=r().subscribe(i);return()=>{i(),n()}}o.createState=s,o.jsx=d,o.render=a,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});