From f8c3d6217fca5cc43eef9402b23f4312a9cafbc4 Mon Sep 17 00:00:00 2001 From: Stephen Date: Sat, 27 Jul 2024 19:54:15 +0200 Subject: [PATCH] include() partially applicable. Moves libs/ into deno/. --- {libs => deno/libs}/marked/marked.min.js | 0 {libs => deno/libs}/prism/prism.css | 0 {libs => deno/libs}/prism/prism.js | 0 {libs => deno/libs}/prism/prism_.js | 0 deno/parse-markdown.js | 4 ++-- modules/renderer/renderer-text.js | 16 ++++++---------- modules/renderer/renderer.js | 11 +++++------ package.json | 2 +- 8 files changed, 14 insertions(+), 19 deletions(-) rename {libs => deno/libs}/marked/marked.min.js (100%) rename {libs => deno/libs}/prism/prism.css (100%) rename {libs => deno/libs}/prism/prism.js (100%) rename {libs => deno/libs}/prism/prism_.js (100%) diff --git a/libs/marked/marked.min.js b/deno/libs/marked/marked.min.js similarity index 100% rename from libs/marked/marked.min.js rename to deno/libs/marked/marked.min.js diff --git a/libs/prism/prism.css b/deno/libs/prism/prism.css similarity index 100% rename from libs/prism/prism.css rename to deno/libs/prism/prism.css diff --git a/libs/prism/prism.js b/deno/libs/prism/prism.js similarity index 100% rename from libs/prism/prism.js rename to deno/libs/prism/prism.js diff --git a/libs/prism/prism_.js b/deno/libs/prism/prism_.js similarity index 100% rename from libs/prism/prism_.js rename to deno/libs/prism/prism_.js diff --git a/deno/parse-markdown.js b/deno/parse-markdown.js index d7cd67cf..9d7c21bf 100644 --- a/deno/parse-markdown.js +++ b/deno/parse-markdown.js @@ -1,11 +1,11 @@ // Markdown library // https://marked.js.org/#/README.md#README.md -import '../libs/marked/marked.min.js'; +import './libs/marked/marked.min.js'; // Syntax highlighter // https://prismjs.com/ -import '../libs/prism/prism.js'; +import './libs/prism/prism.js'; const options = { // GitHub Flavoured Markdown diff --git a/modules/renderer/renderer-text.js b/modules/renderer/renderer-text.js index 8a9eb567..b5bb0383 100644 --- a/modules/renderer/renderer-text.js +++ b/modules/renderer/renderer-text.js @@ -130,7 +130,7 @@ template renderers, or strings. **/ export default class TextRenderer extends Renderer { - static consts = ['data', 'DATA', 'element', 'host', 'shadow', 'include', 'print']; + static consts = ['DATA', 'data', 'element', 'shadow', 'host', 'include', 'print']; constructor(signal, literal, params, element, node, debug) { if (window.DEBUG && !isTextNode(node)) { @@ -138,7 +138,11 @@ export default class TextRenderer extends Renderer { } const consts = assign({}, params, { - include: (...params) => this.include(...params), + // Make a partially applicable include() + include: (url, data) => data === undefined ? + (data) => include(url, data, this.element, this.consts) : + include(url, data, this.element, this.consts), + print: (...args) => print(this, ...args) }); @@ -167,14 +171,6 @@ export default class TextRenderer extends Renderer { return this.contents[this.contents.length - 1]; } - include(url) { - return arguments.length === 1 ? - // Partially applied - (data) => this.include(url, data) : - // Immediate include - include(url, arguments[1], this.element, this.consts) ; - } - evaluate() { if (window.DEBUG) { try { diff --git a/modules/renderer/renderer.js b/modules/renderer/renderer.js index 69bb6c45..db46f9b6 100644 --- a/modules/renderer/renderer.js +++ b/modules/renderer/renderer.js @@ -155,7 +155,7 @@ Renderer(signal, fn, consts, element, name, debug) */ export default class Renderer { - static consts = ['data', 'DATA', 'element', 'shadow', 'host']; + static consts = ['DATA', 'data', 'element', 'shadow', 'host']; #data; #render; @@ -192,14 +192,13 @@ export default class Renderer { // Update template consts. We are ok to do this even if consts is a // shared object, because consts.data and consts.DATA are only accessed // synchronously by #render(). - const consts = this.consts; - consts.data = Data.of(data); - consts.DATA = Data.objectOf(data); - consts.element = this.element; + this.consts.data = Data.of(data); + this.consts.DATA = Data.objectOf(data); + this.consts.element = this.element; // Render! ++this.renderCount; - return render(this, this.#render(consts)); + return render(this, this.#render(this.consts)); } invalidate() { diff --git a/package.json b/package.json index b3ec443e..30cc99fa 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "title": "Literal", "name": "literal", "description": "Literal enhances HTML templates with JS literal expressions for data binding, and provides a declarative way of creating custom elements, all in a small library weighing in at 15kB minified and gzipped.", - "version": "0.9.1", + "version": "0.9.2", "author": { "name": "Stephen Band", "url": "http://stephen.band/",