tivex
Version:
A Small, JSX library for creating Reactive-UIs.
3 lines (2 loc) • 2.6 kB
JavaScript
import{options as r,isElem as t,Fragment as e,$state as n,h as c,$untrack as o,jsxRender as i,cleanup as s,isValidElement as l,propsToProxy as f}from"tivex";function u(r,t,e,n){return new(e||(e=Promise))((function(c,o){function i(r){try{l(n.next(r))}catch(r){o(r)}}function s(r){try{l(n.throw(r))}catch(r){o(r)}}function l(r){var t;r.done?c(r.value):(t=r.value,t instanceof e?t:new e((function(r){r(t)}))).then(i,s)}l((n=n.apply(r,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const a=r=>"function"==typeof r,h=Array.isArray,p=null,d=(...r)=>u(void 0,[...r],void 0,(function*(r=[]){const t=[];for(let e=0;e<r.length;e++){const n=r[e];if(l(n)){let{props:r,type:e}=n;if(a(e))t.push(yield e(f(r)));else{const e=r.children;h(e)&&(n.props.children=yield d(e)),t.push(n)}}else t.push(n)}return t})),v=({children:t,fallback:s})=>{const l=n({v:s}),f=r._err,u=r._ctx;return d(t).then((r=>l.v=r)).catch(f),()=>{const r=c(e,p,l.v);return o((()=>i(r,{err:f,ctx:u})))}},w=r=>t(r)&&r.$c;r.arrDiff=(r,t)=>{let e;return h(r)&&h(t)&&r.length&&(e=t.length)&&((r,t,e)=>{if(!w(r[0])||!w(t[0]))return;let n=r[0].parentNode;if(!n)return;const c=(r,t)=>n.insertBefore(r,t);return(r=r.filter((r=>{const t="d"===r.$c.s;return t&&n.removeChild(r),!t}))).length?(t.forEach((t=>{const{s:n,i:o}=t.$c;if("i"===n){let n,i=r[o];i?(c(t,r[o]),r[o+1]=n=i):c(t,n?n.nextSibling:e)}})),!0):void 0})(t,r,t[e-1].nextSibling)};const x=t=>{const e=t.children,l=e&&e[0];if(!a(l))throw new Error("Cannot find callback");const f=r._err,u=new Map,d=r._ctx;return()=>{const{each:r,fallback:e}=t;if(e&&!r.length)return e;let v;const w=r.map(((r,t,e)=>{const s=n({i:t}),w=()=>s.i;w.peek=()=>t,w.valueOf=w;let x=l(r,w,e),y=(x.props||{}).key;a(y)&&(y=y(),y===w&&(y=p));const g=y||r;if(y&&((v||(v={}))[g]=1),u.has(g)){const r=u.get(g);return r.$c.w.i=t,r.$c.s=p,r}const b=o((()=>(a(x.type)&&h(x.props.children)&&(x=c("t-item",p,x)),i(x,{err:f,ctx:d}))));return b.$c={s:"i",w:s,i:t},u.set(g,b),b}));if(u.size>r.length)for(const[t,e]of u)(v?v[t]:-1!==r.indexOf(t))||(e.$c.s="d",u.delete(t),s(e));return w}},y=r=>()=>{const{when:t,children:n,fallback:o}=r;return c(e,p,t?n:o)},g=r=>()=>{const{children:t,fallback:n}=r;return c(e,p,t.find((r=>r.props.when()))||n)},b=e,k=({children:t,fallback:l})=>{const f=n({v:p}),u=r=>{s(f.v),f.v=h(l(r))},a=r._ctx,h=r=>o((()=>i(r,{err:u,ctx:a})));try{f.v=h(c(e,p,t))}catch(r){u(r)}return()=>f.v},$=({error:r})=>{if(r instanceof Error)throw r;throw new Error(r)};export{k as ErrorBoundary,x as For,b as Match,y as Show,v as Suspense,g as Switch,$ as Throw};
//# sourceMappingURL=flow.js.map