es5-lit-html
Version:
An ES5 transpiled version of lit-html
65 lines (54 loc) • 2.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.render = exports.parts = void 0;
var _dom = require("./dom.js");
var _parts = require("./parts.js");
var _templateFactory = require("./template-factory.js");
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
/**
* @module lit-html
*/
var parts = new WeakMap();
/**
* Renders a template result or other value to a container.
*
* To update a container with new values, reevaluate the template literal and
* call `render` with the new result.
*
* @param result Any value renderable by NodePart - typically a TemplateResult
* created by evaluating a template tag like `html` or `svg`.
* @param container A DOM parent to render to. The entire contents are either
* replaced, or efficiently updated if the same result type was previous
* rendered there.
* @param options RenderOptions for the entire render tree rendered to this
* container. Render options must *not* change between renders to the same
* container, as those changes will not effect previously rendered DOM.
*/
exports.parts = parts;
var render = function render(result, container, options) {
var part = parts.get(container);
if (part === undefined) {
(0, _dom.removeNodes)(container, container.firstChild);
parts.set(container, part = new _parts.NodePart(Object.assign({
templateFactory: _templateFactory.templateFactory
}, options)));
part.appendInto(container);
}
part.setValue(result);
part.commit();
};
exports.render = render;