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) 993 B
/** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */import{render as d,nothing as h}from"../lit-html.js";import{directive as o,Directive as p}from"../directive.js";import{clearPart as m,getCommittedValue as n,insertPart as c,isTemplateResult as i,setCommittedValue as u}from"../directive-helpers.js";class f extends p{constructor(t){super(t),this._templateCache=new WeakMap}render(t){return[t]}update(t,[s]){if(i(this._value)&&(!i(s)||this._value.strings!==s.strings)){const r=n(t).pop();let e=this._templateCache.get(this._value.strings);if(e===void 0){const l=document.createDocumentFragment();e=d(h,l),e.setConnected(!1),this._templateCache.set(this._value.strings,e)}u(e,[r]),c(e,void 0,r)}if(i(s)){if(!i(this._value)||this._value.strings!==s.strings){const a=this._templateCache.get(s.strings);if(a!==void 0){const e=n(a).pop();m(t),c(t,void 0,e),u(t,[e])}}this._value=s}else this._value=void 0;return this.render(s)}}const v=o(f);export{v as cache};