2 lines
3.1 KiB
JavaScript
2 lines
3.1 KiB
JavaScript
import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{Oo as t,vr as n,yr as r}from"./control-ui-core-pH6nakZ-.js";var i;function a(){return(a=e((()=>{r(),i=class{constructor(e,r){this.host=e,this.options=r,this.lifecycle=t({client:null,phase:`stopped`}),this.currentGateway=null,this.currentSnapshot=null,this.currentClient=null,this.currentConnected=!1,this.hasBoundGateway=!1,this.handlePageActivation=()=>{this.options.onPageActivation?.()},this.subscriptions=new n(e).effect(r.getGateway,e=>{let t=!this.hasBoundGateway,n=this.hasBoundGateway&&this.currentGateway!==e;this.hasBoundGateway=!0,this.currentGateway=e,this.applySnapshot(e.snapshot,{initial:t,sourceChanged:n});let r=e.subscribe(t=>{this.currentGateway===e&&this.options.getGateway()===e&&this.applySnapshot(t,{initial:!1,sourceChanged:!1})});return()=>r()}),e.addController(this)}get gateway(){return this.currentGateway}get snapshot(){return this.currentSnapshot}get client(){return this.currentClient}get connected(){return this.currentConnected}get epoch(){return this.lifecycle.epoch}capture(){return this.lifecycle.capture()}isCurrent(e){return this.lifecycle.isCurrent(e)}invalidate(){this.lifecycle.invalidate()}isRouteDataCurrent(e){let t=this.options.getGateway();if(!t||e.gateway!==t)return!1;let n=t.snapshot;return e.gatewaySnapshot===n||e.gatewaySnapshot.phase===`connected`&&n.phase===`connected`&&e.gatewaySnapshot.client===n.client&&e.gatewaySnapshot.hello!==null&&e.gatewaySnapshot.hello===n.hello}hostConnected(){this.options.onPageActivation&&(document.addEventListener(`visibilitychange`,this.handlePageActivation),globalThis.addEventListener(`focus`,this.handlePageActivation))}hostDisconnected(){this.options.onPageActivation&&(document.removeEventListener(`visibilitychange`,this.handlePageActivation),globalThis.removeEventListener(`focus`,this.handlePageActivation)),this.subscriptions.clear();let e=this.currentSnapshot;if(this.currentGateway=null,e){let t={...e,client:null,phase:`stopped`},n=this.lifecycle.transition(t),r=this.currentClient!==null,i=this.currentConnected;this.currentSnapshot=null,this.currentClient=null,this.currentConnected=!1,n&&this.options.invalidateRequests?.({snapshot:t,initial:!1,sourceChanged:!1,clientChanged:r,connectionChanged:i,identityChanged:!1,becameConnected:!1})}else this.lifecycle.invalidate();this.host.requestUpdate()}applySnapshot(e,t){let n=this.currentClient,r=this.currentConnected,i=e.phase===`connected`,a=n!==e.client,o=r!==i,s=this.lifecycle.transition(e);t.sourceChanged&&!s&&this.lifecycle.invalidate(),this.currentSnapshot=e,this.currentClient=e.client,this.currentConnected=i;let c={snapshot:e,initial:t.initial,sourceChanged:t.sourceChanged,clientChanged:a,connectionChanged:o,identityChanged:!t.initial&&(t.sourceChanged||a),becameConnected:i&&!r};c.identityChanged&&this.options.onIdentityChange?.(c),!t.initial&&(s||t.sourceChanged)&&this.options.invalidateRequests?.(c),this.options.onSnapshot?.(c),i&&(t.initial||c.identityChanged||c.connectionChanged)&&this.options.ensureInitialData?.(),this.host.requestUpdate()}}})))()}export{a as n,i as t};
|
|
//# sourceMappingURL=gateway-page-controller-bzyUg03c.js.map
|