@lifeart/gxt
Version:
<img align="right" width="95" height="95" alt="Philosopher’s stone, logo of PostCSS" src="./public/logo.png">
2 lines (1 loc) • 2.24 kB
JavaScript
function t(t){return class extends s{suspenseContext=null;suspenseStarted=!1;loadingPromise;constructor(t){super(t),this.params=t,this[m]=this._template,this.loadingPromise=this.load(),x(this,()=>this.loadingPromise.catch(()=>{}))}params={};stateCell=c({loading:!0,error:null,component:null});get isLoading(){return this.stateCell.value.loading}get error(){return this.stateCell.value.error}get contentComponent(){return this.stateCell.value.component}async load(){try{const{default:s}=await t();if(g(this))return;this.stateCell.update({loading:!1,error:null,component:s}),this.suspenseContext?.end()}catch(s){if(g(this))return;this.stateCell.update({loading:!1,error:s,component:null}),this.suspenseContext?.end()}}_template(){return this.suspenseStarted||(this.suspenseStarted=!0,this.suspenseContext=p(this,v,!1),queueMicrotask(()=>{!g(this)&&this.isLoading&&this.suspenseContext?.start()})),a([r(()=>this.isLoading,()=>null,t=>{if(this.error)throw this.error;return d(this.contentComponent,this.params,t)},this)],this)}}}import{C as s}from"./component-class-DA1pm8lP.js";import{W as e,b as n,e as i,U as l,u as a,z as r,G as o,E as u,ag as h,m as d,P as p}from"./dom-BiflCx2O.js";import{b as m,e as c,J as g,R as C,r as x}from"./vm-CFZXVoe9.js";import{S as v}from"./suspense-utils-ClcJa2UW.js";export{f as followPromise}from"./suspense-utils-ClcJa2UW.js";class A extends s{constructor(){super(...arguments),e(this,v,this),this[m]=this._template}pendingAmountCell=c(0);isReleasedCell=c(!1);get pendingAmount(){return this.pendingAmountCell.value}get isReleased(){return this.isReleasedCell.value}start(){g(this)||this.isReleased||this.pendingAmountCell.update(this.pendingAmountCell.value+1)}end(){if(g(this)||this.isReleased)return;const t=this.pendingAmountCell.value;if(t<=0)return;const s=t-1;this.pendingAmountCell.update(s),0===s&&this.isReleasedCell.update(!0)}get fallback(){return this.args.fallback}_template(){n(this,arguments);const t=i(this,arguments);let s=null;const e=l(this);let p=e.fragment();return a([r(()=>this.isReleased,()=>({[C]:Array.from(p.childNodes)}),n=>(null===s&&(s=o(s=>u("default",()=>[],t,s)[C],n),h(e,s,p,s,null)),d(this.fallback,{},n)),this)],this)}}export{v as SUSPENSE_CONTEXT,A as Suspense,t as lazy};