Skip to content

Commit

Permalink
Tings
Browse files Browse the repository at this point in the history
  • Loading branch information
stephband committed Jan 19, 2024
1 parent 4779b2a commit eb49d14
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion module.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function Literal(template) {
// which is what we want to do. Instead it creates a new renderer...

template = typeof template === 'string' ?
document.getElementById(template) :
document.getElementById(template.slice(1)) :
template ;

return new TemplateRenderer(template);
Expand Down
9 changes: 5 additions & 4 deletions modules/renderer-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const assign = Object.assign;
const keys = Object.keys;
const cache = {};
const nodes = [];
const defaults = {};


function dataToString() {
Expand Down Expand Up @@ -132,12 +133,12 @@ function createRenderer(Renderer) {
return renderer;
}

export default function TemplateRenderer(template, element = template.parentElement, parameters = {}) {
export default function TemplateRenderer(template, element = template.parentElement, parameters = {}, options = defaults) {
const id = identify(template) ;

const { content, renderers } = cache[id]
|| (cache[id] = compileTemplate(template, id, {
nostrict: template.hasAttribute('nostrict')
const { content, renderers } = cache[id] ||
(cache[id] = compileTemplate(template, id, {
nostrict: options.nostrict || (template.hasAttribute && template.hasAttribute('nostrict'))
}));

this.element = element;
Expand Down
6 changes: 3 additions & 3 deletions modules/renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,21 @@ function renderValue(renderer, args, values, n, object, isRender = false) {
return;
}

// Is target a Stream?
// Is target a pipeable Stream?
if (target.pipe) {
const streams = renderer.streams || (renderer.streams = []);
values[n] = '';
// Do not render synchronous values that are in the stream
// immediately, as they are about to be rendered by the renderer
let isRender = false;
target.each((value) => renderValue(renderer, args, values, n, value, isRender));
target.pipe({ push: (value) => renderValue(renderer, args, values, n, value, isRender) });
isRender = true;
streams.push(target);
return;
}

// Is target a Stream that is already consumed, and therefore does not
// have .each()? We still want to stop it when the renderer is
// have .pipe()? We still want to stop it when the renderer is
// destroyed, but we don't want to renderer anything.
if (Stream.isStream(target)) {
const streams = renderer.streams || (renderer.streams = []);
Expand Down
1 change: 1 addition & 0 deletions modules/renderer/to-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ const toText = overload(toType, {
// Convert NaN to empty string and Infinity to ∞ symbol
Number.isNaN(value) ? '' :
Number.isFinite(value) ? value :
value === Math.PI ? '' :
value < 0 ? '-∞' : '∞'
),

Expand Down

0 comments on commit eb49d14

Please sign in to comment.