Skip to content

Commit 4023a0a

Browse files
committed
uhtml/ssr - Added both easy SSR and worker.js target
1 parent a6f032c commit 4023a0a

File tree

15 files changed

+221
-106
lines changed

15 files changed

+221
-106
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ types/
55
cjs/*
66
!cjs/package.json
77
dom.js
8-
esm/init.js
9-
init.js
8+
esm/init*.js
9+
init*.js
10+
worker.js
1011
keyed.js
1112
!esm/keyed.js
1213
!esm/dom/keyed.js
@@ -24,4 +25,4 @@ signal.js
2425
!esm/signal.js
2526
!esm/render/signal.js
2627
preactive.js
27-
!test/preactive.js
28+
!test/preactive.js

esm/creator.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
import { PersistentFragment } from './persistent-fragment.js';
22
import { bc, detail } from './literals.js';
33
import { array, hole } from './handler.js';
4-
import { empty } from './utils.js';
4+
import { empty, find } from './utils.js';
55
import { cache } from './literals.js';
66

7-
/**
8-
* @param {DocumentFragment} content
9-
* @param {number[]} path
10-
* @returns {Element}
11-
*/
12-
const find = (content, path) => path.reduceRight(childNodesIndex, content);
13-
const childNodesIndex = (node, i) => node.childNodes[i];
14-
157
/** @param {(template: TemplateStringsArray, values: any[]) => import("./parser.js").Resolved} parse */
168
export default parse => (
179
/**

esm/persistent-fragment.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class PersistentFragment extends custom(DocumentFragment) {
5050
remove(this, true).replaceWith(node);
5151
}
5252
valueOf() {
53-
let { firstChild, lastChild, parentNode } = this;
53+
const { parentNode } = this;
5454
if (parentNode === this) {
5555
if (this.#nodes === empty)
5656
this.#nodes = [...this.childNodes];
@@ -65,6 +65,7 @@ export class PersistentFragment extends custom(DocumentFragment) {
6565
// This is a render-only specific issue but it's tested and
6666
// it's worth fixing to me to have more consistent fragments.
6767
if (parentNode) {
68+
let { firstChild, lastChild } = this;
6869
this.#nodes = [firstChild];
6970
while (firstChild !== lastChild)
7071
this.#nodes.push((firstChild = firstChild.nextSibling));

esm/rabbit.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { cache } from './literals.js';
33
import create from './creator.js';
44
import parser from './parser.js';
55

6-
const parseHTML = create(parser(false));
7-
const parseSVG = create(parser(true));
6+
const createHTML = create(parser(false));
7+
const createSVG = create(parser(true));
88

99
/**
1010
* @param {import("./literals.js").Cache} info
@@ -13,7 +13,7 @@ const parseSVG = create(parser(true));
1313
*/
1414
const unroll = (info, { s, t, v }) => {
1515
if (info.a !== t) {
16-
const { b, c } = (s ? parseSVG : parseHTML)(t, v);
16+
const { b, c } = (s ? createSVG : createHTML)(t, v);
1717
info.a = t;
1818
info.b = b;
1919
info.c = c;

esm/ssr.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Hole, render, html, svg, attr } from './index.js';
2+
3+
const htmlFor = () => html;
4+
const svgFor = () => svg;
5+
6+
export { Hole, render, html, svg, htmlFor, svgFor, attr };

esm/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,13 @@ export const gPD = (ref, prop) => {
3434
while(!desc && (ref = getPrototypeOf(ref)));
3535
return desc;
3636
};
37+
38+
/* c8 ignore start */
39+
/**
40+
* @param {DocumentFragment} content
41+
* @param {number[]} path
42+
* @returns {Element}
43+
*/
44+
export const find = (content, path) => path.reduceRight(childNodesIndex, content);
45+
const childNodesIndex = (node, i) => node.childNodes[i];
46+
/* c8 ignore stop */

package-lock.json

Lines changed: 69 additions & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)