UNPKG

@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) 953 B
/** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */import{noChange as c}from"../lit-html.js";import{AsyncDirective as u,directive as o}from"../async-directive.js";import{Pauser as h,PseudoWeakRef as d,forAwaitOf as p}from"./private-async-helpers.js";class f extends u{constructor(){super(...arguments),this.__weakThis=new d(this),this.__pauser=new h}render(t,e){return c}update(t,[e,n]){if(this.isConnected||this.disconnected(),e===this.__value)return;this.__value=e;let s=0;const{__weakThis:_,__pauser:a}=this;return p(e,async i=>{for(;a.get();)await a.get();const r=_.deref();if(r!==void 0){if(r.__value!==e)return!1;n!==void 0&&(i=n(i,s)),r.commitValue(i,s),s++}return!0}),c}commitValue(t,e){this.setValue(t)}disconnected(){this.__weakThis.disconnect(),this.__pauser.pause()}reconnected(){this.__weakThis.reconnect(this),this.__pauser.resume()}}const T=o(f);export{f as AsyncReplaceDirective,T as asyncReplace};