@popeindustries/lit-html
Version:
Seamlessly and efficiently use @popeindustries/lit-html-server rendered HTML to hydrate lit-html templates in the browser
6 lines (5 loc) • 1.3 kB
JavaScript
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/import{noChange as h}from"../lit-html.js";import{isPrimitive as p}from"../directive-helpers.js";import{directive as v,AsyncDirective as m}from"../async-directive.js";import{Pauser as x,PseudoWeakRef as w}from"./private-async-helpers.js";const u=r=>!p(r)&&typeof r.then=="function",c=1073741823;class k extends m{constructor(){super(...arguments),this.__lastRenderedIndex=c,this.__values=[],this.__weakThis=new w(this),this.__pauser=new x}render(...o){var e;return(e=o.find(n=>!u(n)))!==null&&e!==void 0?e:h}update(o,e){const n=this.__values;let d=n.length;this.__values=e;const f=this.__weakThis,a=this.__pauser;this.isConnected||this.disconnected();for(let t=0;t<e.length&&!(t>this.__lastRenderedIndex);t++){const s=e[t];if(!u(s))return this.__lastRenderedIndex=t,s;t<d&&s===n[t]||(this.__lastRenderedIndex=c,d=0,Promise.resolve(s).then(async l=>{for(;a.get();)await a.get();const i=f.deref();if(i!==void 0){const _=i.__values.indexOf(s);_>-1&&_<i.__lastRenderedIndex&&(i.__lastRenderedIndex=_,i.setValue(l))}}))}return h}disconnected(){this.__weakThis.disconnect(),this.__pauser.pause()}reconnected(){this.__weakThis.reconnect(this),this.__pauser.resume()}}const T=v(k);export{k as UntilDirective,T as until};