@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) • 904 B
JavaScript
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/import{noChange as n,nothing as s}from"../lit-html.js";import{directive as T,Directive as c,PartType as t}from"../directive.js";import{isSingleExpression as m,setCommittedValue as E}from"../directive-helpers.js";class d extends c{constructor(e){if(super(e),!(e.type===t.PROPERTY||e.type===t.ATTRIBUTE||e.type===t.BOOLEAN_ATTRIBUTE))throw new Error("The `live` directive is not allowed on child or event bindings");if(!m(e))throw new Error("`live` bindings can only contain a single expression")}render(e){return e}update(e,[i]){if(i===n||i===s)return i;const r=e.element,o=e.name;if(e.type===t.PROPERTY){if(i===r[o])return n}else if(e.type===t.BOOLEAN_ATTRIBUTE){if(!!i===r.hasAttribute(o))return n}else if(e.type===t.ATTRIBUTE&&r.getAttribute(o)===String(i))return n;return E(e),i}}const A=T(d);export{A as live};