MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / _setupReactiveEffect

Method _setupReactiveEffect

www/js/_hyperscript-max.min.js:395–395  ·  view source on GitHub ↗
(I)

Source from the content-addressed store, hash-verified

393 `;j.prototype.ui=function(){var s=document.createElement("div"),e=s.attachShadow({mode:"open"});s.style.cssText="all: initial",e.innerHTML=qn,document.body.appendChild(s),this._hyperscript.process(e.querySelector(".hdb"))};function Wi(s){s.addCommand(ee.keyword,ee.parse.bind(ee))}typeof self<"u"&&self._hyperscript&&self._hyperscript.use(Wi);function Ui(s){let{runtime:e,createParser:t,reactivity:r}=s.internals,i=new M;function n(){if(!(typeof document>"u"||!document.head)&&!document.head.querySelector('style[data-hyperscript-component="fouce-guard"]')){var h=document.createElement("style");h.setAttribute("data-hyperscript-component","fouce-guard"),h.textContent=":not(:defined) { visibility: hidden; }",document.head.appendChild(h)}}function o(h,d,v){if(!d)return h;var k=document.createElement("div");k.innerHTML=d;var T={},w=[];for(var E of Array.from(k.childNodes)){E.nodeType===1&&v&&!E.hasAttribute("dom-scope")&&E.setAttribute("dom-scope","parent of "+v);var x=E.nodeType===1&&E.getAttribute("slot");x?(E.removeAttribute("slot"),T[x]||(T[x]=""),T[x]+=E.outerHTML):w.push(E.nodeType===1?E.outerHTML:E.nodeType===3?E.textContent:"")}var L=w.join(""),A=h.replace(/<slot\s+name\s*=\s*["']([^"']+)["']\s*\/?\s*>(\s*<\/slot>)?/g,function(I,_){return T[_]||""});return A=A.replace(/<slot\s*\/?\s*>(\s*<\/slot>)?/g,L),A}function a(h,d){if(typeof d!="string")return null;var v=h._attrsCache||(h._attrsCache={});if(!v[d]){var k=h.getAttribute(d);if(k==null)return null;try{v[d]=t(i.tokenize(k)).requireElement("expression")}catch(T){return console.error("component: failed to parse attrs."+d+":",T.message),null}}return v[d]}function l(h){var d=h.parentElement;return d?e.makeContext(d,null,d,null):null}function u(h){return new Proxy({_hsSkipTracking:!0},{get:function(d,v){if(v==="_hsSkipTracking")return!0;if(!(typeof v!="string"||v.startsWith("_"))){var k=a(h,v);if(k){var T=l(h);return T?k.evaluate(T):void 0}}},set:function(d,v,k){var T=a(h,v);if(!T||!T.set)return!1;var w=l(h);if(!w)return!1;var E={};if(T.lhs)for(var x in T.lhs){var L=T.lhs[x];E[x]=L&&L.evaluate?L.evaluate(w):L}return T.set(w,E,k),!0}})}function c(h,d){let v=h.getAttribute("component");if(!v.includes("-")){console.error("component name must contain a dash: '"+v+"'");return}for(var k=h.textContent,T="",w=/<style[^>]*>([\s\S]*?)<\/style>/gi,E;(E=w.exec(k))!==null;)T+=E[1]+`
394`;if(T){k=k.replace(/<style[^>]*>[\s\S]*?<\/style>/gi,""),h.textContent=k;var x=document.createElement("style");x.setAttribute("data-hyperscript-component",v),x.textContent="@scope ("+v+`) {
395`+T+"}",document.head.appendChild(x)}let L=h.textContent,A=class extends HTMLElement{connectedCallback(){if(this._hypercomp_initialized)return;this._hypercomp_initialized=!0,this.setAttribute("dom-scope","isolated"),this._slotContent=this.innerHTML,this.innerHTML="";var I=e.getInternalData(this);I.elementScope||(I.elementScope={}),I.elementScope.attrs=u(this),d&&(this.setAttribute("_",d),s.process(this));let _=this;var F=o(L,_._slotContent,v);queueMicrotask(function(){var U=_._renderTemplate(F);U&&U.then?U.then(function(B){_._stampTemplate(B),_._setupReactiveEffect(F)}):(_._stampTemplate(U),_._setupReactiveEffect(F))})}disconnectedCallback(){r.stopElementEffects(this),e.cleanup(this),this._hypercomp_initialized=!1,this._hypercomp_stamped=!1}_setupReactiveEffect(I){var _=this;r.createEffect(function(){return _._renderTemplate(I)},function(F){_._stampTemplate(F)},{element:_})}_renderTemplate(I){var _=e.makeContext(this,null,this,null),F=[];_.meta.__ht_template_result=F;var U=i.tokenize(I,"lines"),B=t(U),Q;try{Q=B.parseElement("commandList"),B.ensureTerminated(Q)}catch(le){return console.error("hypercomp template parse error:",le.message||le),""}var se,oe,ae=new Promise(function(le,Zi){se=le,oe=Zi});return Q.execute(_),this.__hs_scopes=_.meta.__ht_scopes||null,_.meta.returned||!_.meta.resolve?F.join(""):(_.meta.resolve=se,_.meta.reject=oe,ae.then(function(){return F.join("")}))}_stampTemplate(I){this._hypercomp_stamped?e.morph(this,I):(this.innerHTML=I,s.process(this),this._hypercomp_stamped=!0)}};customElements.define(v,A)}var f=new Set,p=new Map;function m(h){var d=h.getAttribute("component");if(!(!d||f.has(d)||customElements.get(d))){f.add(d);var v=h.hasOwnProperty("_componentScript")?h._componentScript:h.getAttribute("_")||"";h.hasAttribute("_")&&h.removeAttribute("_"),c(h,v||"")}}function y(h){if(p.has(h))return p.get(h);var d=fetch(h).then(function(v){if(!v.ok)throw new Error("HTTP "+v.status+" fetching "+h);return v.text()}).then(function(v){var k=new DOMParser().parseFromString(v,"text/html");for(let T of k.querySelectorAll('script[type="text/hyperscript-template"][component]'))m(T)}).catch(function(v){console.error("hyperscript component bundle '"+h+"': "+v.message),p.delete(h)});return p.set(h,d),d}s.addBeforeProcessHook(function(h){n(),!(!h||!h.querySelectorAll)&&h.querySelectorAll('script[type="text/hyperscript-template"][component]').forEach(function(d){"_componentScript"in d||(d._componentScript=d.getAttribute("_")||"",d.removeAttribute("_"))})}),s.addAfterProcessHook(function(h){if(!(!h||!h.querySelectorAll)){for(var d of h.querySelectorAll('script[type="text/hyperscript-template"][component]'))m(d);for(var v of h.querySelectorAll('script[type="text/hyperscript-component"][src]'))v._componentBundleLoaded||(v._componentBundleLoaded=!0,y(v.getAttribute("src")))}})}typeof self<"u"&&self._hyperscript&&self._hyperscript.use(Ui);function Nn(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(s){var e=Math.random()*16|0,t=s=="x"?e:e&3|8;return t.toString(16)})}function Bi(s){var e=s;if(e.startsWith("/")){var t=window.location.hostname+(window.location.port?":"+window.location.port:"");window.location.protocol==="https:"?e="wss://"+t+e:window.location.protocol==="http:"&&(e="ws://"+t+e)}return e}var An=["then","catch","length","toJSON"],te=class s extends q{static keyword="socket";constructor(e,t,r,i){super(),this.socketName=e,this.nameSpace=t,this.socketObject=r,this.messageHandler=i}install(e,t,r,i){this.runtime=i,i.assignToNamespace(e,this.nameSpace,this.socketName,this.socketObject)}static parse(e){if(!e.matchToken("socket"))return;var t=e.requireElement("dotOrColonPath"),r=t.evalStatically(),i=r.split("."),n=i.pop(),o={},a=e.parseURLOrExpression(),l=1e4;e.matchToken("with")&&(e.requireToken("timeout"),l=e.requireElement("expression").evalStatically());var u=!1,c=null;e.matchToken("on")&&(e.requireToken("message"),e.matchToken("as")&&(e.matchToken("JSON")||e.requireToken("json"),u=!0),c=e.requireElement("commandList"),e.ensureTerminated(c));var f=new WebSocket(Bi(a.evalStatically()));function p(d){return new Proxy({},{get:function(v,k){return An.includes(k)?null:k==="noTimeout"?p(-1):k==="timeout"?function(T){return p(parseInt(T))}:function(){for(var T=Nn(),w=[],E=0;E<arguments.length;E++)w.push(arguments[E]);var x={iid:T,function:k,args:w};f=f||new WebSocket(Bi(a.evalStatically())),f.send(JSON.stringify(x));var L=new Promise(function(A,I){o[T]={resolve:A,reject:I}});return d>=0&&setTimeout(function(){o[T]&&o[T].reject("Timed out"),delete o[T]},d),L}}})}var m=p(l),y={raw:f,dispatchEvent:function(d){var v=d.detail;delete v.sender,delete v._namedArgList_,f.send(JSON.stringify(Object.assign({type:d.type},v)))},rpc:m},h=new s(n,i,y,c);return f.onmessage=function(d){var v=d.data;try{var k=JSON.parse(v)}catch{}if(k&&k.iid&&(k.throw?o[k.iid].reject(k.throw):o[k.iid].resolve(k.return),delete o[k.iid]),c){var T=h.runtime.makeContext(y,h,y);if(u)if(k)T.locals.message=k,T.result=k;else throw new Error("Received non-JSON message from socket: "+v);else T.locals.message=v,T.result=v;c.execute(T)}},f.addEventListener("close",function(d){f=null}),c&&e.setParent(c,h),h}};function zi(s){s.addFeature(te.keyword,te.parse.bind(te))}typeof self<"u"&&self._hyperscript&&self._hyperscript.use(zi);var Ln=0,_n=function(s){s.onmessage=function(e){switch(e.data.type){case"init":s.importScripts(e.data._hyperscript),s.importScripts.apply(s,e.data.extraScripts);var t=s._hyperscript.parse(e.data.src);t.apply(s,s),postMessage({type:"didInit"});break;case"call":try{var r=s._hyperscript.internals.runtime.getHyperscriptFeatures(s)[e.data.function].apply(s,e.data.args);Promise.resolve(r).then(function(n){postMessage({type:"resolve",id:e.data.id,value:n})}).catch(function(n){postMessage({type:"reject",id:e.data.id,error:n.toString()})})}catch(n){postMessage({type:"reject",id:e.data.id,error:n.toString()})}break}}},In="("+_n.toString()+")(self)",On=new Blob([In],{type:"text/javascript"}),Mn=URL.createObjectURL(On),re=class s extends q{static keyword="worker";constructor(e,t,r,i){super(),this.workerName=e,this.name=e,this.nameSpace=t,this.worker=r,this.stubs=i}static parse(e){if(e.matchToken("worker")){var t=e.requireElement("dotOrColonPath"),r=t.evalStatically(),i=r.split("."),n=i.pop(),o=[];if(e.matchOpToken("(")&&!e.matchOpToken(")")){do{var a=e.requireTokenType("STRING").value,l=new URL(a,location.href).href;o.push(l)}while(e.matchOpToken(","));e.requireOpToken(")")}var u=[],c=e.consumed.length,f=e.consumed.length;do{var p=e.parseAnyOf(["defFeature","jsFeature"]);if(p){if(p.type==="defFeature")u.push(p.name),f=e.consumed.length;else if(e.hasMore())continue}else break}while(e.matchToken("end")&&e.hasMore());var m=e.consumed.slice(c,f+1),y=e.source.substring(m[0].start,m[m.length-1].end),h=new Worker(Mn);h.postMessage({type:"init",_hyperscript:document.currentScript?.src||"/dist/_hyperscript.js",extraScripts:o,src:y});var d=new Promise(function(k,T){h.addEventListener("message",function(w){w.data.type==="didInit"&&k()},{once:!0})}),v={};return u.forEach(function(k){v[k]=function(){var T=arguments;return new Promise(function(w,E){var x=Ln++;h.addEventListener("message",function L(A){A.data.id===x&&(h.removeEventListener("message",L),A.data.type==="resolve"?w(A.data.value):E(A.data.error))}),d.then(function(){h.postMessage({type:"call",function:k,args:Array.from(T),id:x})})})}}),new s(n,i,h,v)}}install(e,t,r,i){i.assignToNamespace(e,this.nameSpace,this.workerName,this.stubs)}};function Gi(s){s.addFeature(re.keyword,re.parse.bind(re))}typeof self<"u"&&self._hyperscript&&self._hyperscript.use(Gi);async function*$i(s){var e=new TextDecoder,t="",r=!1,i={data:"",event:"",id:"",retry:null},n=!0;try{for(;;){var{done:o,value:a}=await s.read();if(o)break;var l=e.decode(a,{stream:!0});n&&(l.charCodeAt(0)===65279&&(l=l.slice(1)),n=!1),t+=l;var u=t.split(/\r\n|\r|\n/);t=u.pop()||"";for(var c=0;c<u.length;c++){var f=u[c];if(!f){r&&(yield i,r=!1,i={data:"",event:"",id:"",retry:null});continue}var p=f.indexOf(":");if(p!==0){var m,y;if(p<0?(m=f,y=""):(m=f.slice(0,p),y=f.slice(p+1),y[0]===" "&&(y=y.slice(1))),m==="data")i.data+=(r?`
396`:"")+y,r=!0;else if(m==="event")i.event=y;else if(m==="id")y.includes("\0")||(i.id=y);else if(m==="retry"){var h=parseInt(y,10);isNaN(h)||(i.retry=h)}}}}}finally{s.releaseLock()}}function Cn(s,e){if(s===e)return!0;if(!s.includes("*"))return!1;var t=new RegExp("^"+s.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")+"$");return t.test(e)}var ie=class s extends q{static keyword="eventsource";constructor(e,t,r){super(),this.eventSourceName=e,this.nameSpace=t,this.stub=r}install(e,t,r,i){this.runtime=i,i.assignToNamespace(e,this.nameSpace,this.eventSourceName,this.stub)}static parse(e){if(e.matchToken("eventsource")){var t,r=!1,i="GET",n=null,o=e.requireElement("dotOrColonPath"),a=o.evalStatically(),l=a.split("."),u=l.pop();for(e.matchToken("from")&&(t=e.parseURLOrExpression());e.matchToken("with");)e.matchToken("credentials")?r=!0:e.matchToken("method")?i=e.requireElement("stringLike").evalStatically().toUpperCase():e.matchToken("headers")?n=e.requireElement("objectLiteral"):e.raiseExpected("credentials","method","headers");var c=null;if(n){c={};for(var f=0;f<n.keyExpressions.length;f++){var p=n.keyExpressions[f].evalStatically(),m=n.valueExpressions[f].evalStatically();c[p]=m}}for(var y=Fn(r,i,c),h=new s(u,l,y);e.matchToken("on");){var d=e.requireElement("stringLike").evalStatically(),v="";e.matchToken("as")&&(v=e.requireElement("stringLike").evalStatically());var k=e.requireElement("commandList");e.ensureTerminated(k),e.requireToken("end"),y.listeners.push({type:d,handler:Pn(v,k,y,h)})}return e.requireToken("end"),t!=null&&y.open(t.evalStatically()),h}}};function Fn(s,e,t){var r={listeners:[],retryCount:0,closed:!1,abortController:null,reader:null,lastEventId:null,reconnectTimeout:null,url:null,withCredentials:s,method:e,headers:t,open:function(i){if(i==null)if(r.url!=null)i=r.url;else throw new Error("no url defined for EventSource.");r.url===i&&r.abortController&&!r.abortController.signal.aborted||(r.abortController&&r.abortController.abort(),r.closed=!1,r.url=i,Qi(r))},close:function(){r.closed=!0,r.reconnectTimeout&&(clearTimeout(r.reconnectTimeout),r.reconnectTimeout=null),r.abortController&&(r.abortController.abort(),r.abortController=null),r.retryCount=0,ne(r,"close",{type:"close"})},addEventListener:function(i,n,o){r.listeners.push({type:i,handler:n,options:o})}};return r}function Qi(s){var e=new AbortController;s.abortController=e;var t={method:s.method,signal:e.signal,headers:Object.assign({},s.headers||{})};s.withCredentials&&(t.credentials="include"),s.lastEventId&&(t.headers["Last-Event-ID"]=s.lastEventId),fetch(s.url,t).then(function(r){if(!e.signal.aborted){if(!r.ok)throw new Error("SSE connection failed with status "+r.status);return s.retryCount=0,ne(s,"open",{type:"open"}),Rn(s,r.body.getReader(),e)}}).catch(function(r){e.signal.aborted||(ne(s,"error",{type:"error",error:r}),Yi(s))})}async function Rn(s,e,t){s.reader=e;var r=500;try{for await(var i of $i(e)){if(t.signal.aborted)break;i.id&&(s.lastEventId=i.id),i.retry!=null&&(r=i.retry);var n=i.event||"message",o={type:n,data:i.data,lastEventId:i.id||s.lastEventId||""};ne(s,n,o)}}catch(a){t.signal.aborted||ne(s,"error",{type:"error",error:a})}s.reader=null,!s.closed&&!t.signal.aborted&&Yi(s,r)}function Yi(s,e){if(!s.closed){e=e||500,s.retryCount=Math.min(7,s.retryCount+1);var t=Math.random()*2**s.retryCount*e;s.reconnectTimeout=setTimeout(function(){s.reconnectTimeout=null,s.closed||Qi(s)},t)}}function ne(s,e,t){for(var r=0;r<s.listeners.length;r++){var i=s.listeners[r];if(Cn(i.type,e))try{i.handler(t)}catch(n){console.error("Error in SSE handler for '"+i.type+"':",n)}}}function Pn(s,e,t,r){return function(i){var n=Hn(i.data,s),o=r.runtime.makeContext(t,r,t);o.event=i,o.result=n,e.execute(o)}}function Hn(s,e){return e.toLowerCase()==="json"?JSON.parse(s):s}function Dn(s,e,t){var r=t.me,i=s.body.getReader(),n=[],o=null,a=!1;(async function(){try{for await(var u of $i(i)){var c=u.event||"message";u.event?e.triggerEvent(r,c,{data:u.data,lastEventId:u.id||""}):(n.push(u.data),o&&(o.resolve({value:u.data,done:!1}),o=null))}}catch(f){e.triggerEvent(r,"stream-error",{error:f})}a=!0,o&&(o.resolve({value:void 0,done:!0}),o=null),e.triggerEvent(r,"streamEnd",{})})();var l={element:r,[Symbol.asyncIterator]:function(){var u=0;return{next:function(){return u<n.length?Promise.resolve({value:n[u++],done:!1}):a?Promise.resolve({value:void 0,done:!0}):new Promise(function(c){o={resolve:c}}).then(function(c){return c.done||u++,c})}}}};return l}var Xi=function(s,e,t){return Dn(s,e,t)};Xi._rawResponse=!0;function Ki(s){s.addFeature(ie.keyword,ie.parse.bind(ie)),s.config.conversions.Stream=Xi,addEventListener("hyperscript:beforeFetch",function(e){e.detail.conversion==="Stream"&&(e.detail.headers.Accept="text/event-stream")})}typeof self<"u"&&self._hyperscript&&self._hyperscript.use(Ki);function Ji(s){s.config.hideShowStrategies={twDisplay:function(e,t,r){e==="toggle"?t.classList.contains("hidden")?s.config.hideShowStrategies.twDisplay("show",t,r):s.config.hideShowStrategies.twDisplay("hide",t,r):e==="hide"?t.classList.add("hidden"):t.classList.remove("hidden")},twVisibility:function(e,t,r){e==="toggle"?t.classList.contains("invisible")?s.config.hideShowStrategies.twVisibility("show",t,r):s.config.hideShowStrategies.twVisibility("hide",t,r):e==="hide"?t.classList.add("invisible"):t.classList.remove("invisible")},twOpacity:function(e,t,r){e==="toggle"?t.classList.contains("opacity-0")?s.config.hideShowStrategies.twOpacity("show",t,r):s.config.hideShowStrategies.twOpacity("hide",t,r):e==="hide"?t.classList.add("opacity-0"):t.classList.remove("opacity-0")}}}typeof self<"u"&&self._hyperscript&&self._hyperscript.use(Ji);})();

Callers 1

connectedCallbackMethod · 0.45

Calls 3

createEffectMethod · 0.45
_renderTemplateMethod · 0.45
_stampTemplateMethod · 0.45

Tested by

no test coverage detected