@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.28 kB
JavaScript
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/import{nothing as f}from"../lit-html.js";import{directive as o,AsyncDirective as r}from"../async-directive.js";const u=()=>new a;class a{}const s=new WeakMap;class d extends r{render(e){return f}update(e,[t]){var i;const n=t!==this._ref;return n&&this._ref!==void 0&&this._updateRefValue(void 0),(n||this._lastElementForRef!==this._element)&&(this._ref=t,this._context=(i=e.options)===null||i===void 0?void 0:i.host,this._updateRefValue(this._element=e.element)),f}_updateRefValue(e){var t;if(typeof this._ref=="function"){const i=(t=this._context)!==null&&t!==void 0?t:globalThis;let n=s.get(i);n===void 0&&(n=new WeakMap,s.set(i,n)),n.get(this._ref)!==void 0&&this._ref.call(this._context,void 0),n.set(this._ref,e),e!==void 0&&this._ref.call(this._context,e)}else this._ref.value=e}get _lastElementForRef(){var e,t,i;return typeof this._ref=="function"?(t=s.get((e=this._context)!==null&&e!==void 0?e:globalThis))===null||t===void 0?void 0:t.get(this._ref):(i=this._ref)===null||i===void 0?void 0:i.value}disconnected(){this._lastElementForRef===this._element&&this._updateRefValue(void 0)}reconnected(){this._updateRefValue(this._element)}}const c=o(d);export{u as createRef,c as ref};