Skip to content

Commit

Permalink
include() partially applicable. Moves libs/ into deno/.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephband committed Jul 27, 2024
1 parent b0310d7 commit f8c3d62
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 19 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions deno/parse-markdown.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 6 additions & 10 deletions modules/renderer/renderer-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,19 @@ 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)) {
throw new TypeError('TextRenderer() node not a text node');
}

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)
});

Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 5 additions & 6 deletions modules/renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down

0 comments on commit f8c3d62

Please sign in to comment.