Skip to content

Commit

Permalink
reduce output size
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed Jun 12, 2019
1 parent e342687 commit 4c1eb15
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 47 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dom-expressions",
"description": "A Fine-Grained Runtime for Performant DOM Rendering",
"version": "0.9.9",
"version": "0.9.10",
"author": "Ryan Carniato",
"license": "MIT",
"repository": {
Expand Down
69 changes: 24 additions & 45 deletions template/runtime.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -261,27 +261,22 @@ export function when(parent, accessor, expr, options, marker) {
return sample(() => {
parent = (marker && marker.parentNode) || (beforeNode && beforeNode.parentNode) || parent;
disposable && disposable();
clearAll(parent, current, marker, beforeNode && beforeNode.nextSibling);
current = null;
if (value == null || value === false) {
clearAll(parent, current, marker, beforeNode && beforeNode.nextSibling);
current = null;
afterRender && afterRender(current, marker);
if (fallback) {
root(disposer => {
disposable = disposer;
const rendered = fallback();
if (typeof rendered !== 'function') current = insertExpression(parent, rendered, current, marker);
else wrap(() => current = insertExpression(parent, rendered(), current, marker));
addNode(parent, fallback(), marker, ++groupCounter, node => current = node);
});
}
return value;
} else {
root(disposer => {
disposable = disposer;
addNode(parent, expr(value), marker, ++groupCounter, node => current = node, afterRender && afterRender(node, marker));
});
}
root(disposer => {
disposable = disposer;
const rendered = expr(value);
if (typeof rendered !== 'function') current = insertExpression(parent, rendered, current, marker);
else wrap(() => current = insertExpression(parent, rendered(), current, marker));
});
afterRender && afterRender(current, marker);
return value;
});
});
Expand All @@ -306,27 +301,22 @@ export function switchWhen(parent, conditions, _, options, marker) {
return sample(() => {
parent = (marker && marker.parentNode) || (beforeNode && beforeNode.parentNode) || parent;
disposable && disposable();
clearAll(parent, current, marker, beforeNode && beforeNode.nextSibling);
current = null;
if (index < 0) {
clearAll(parent, current, marker, beforeNode && beforeNode.nextSibling);
current = null;
afterRender && afterRender(current, marker);
afterRender && afterRender(null, marker);
if (fallback) {
root(disposer => {
disposable = disposer;
const rendered = fallback();
if (typeof rendered !== 'function') current = insertExpression(parent, rendered, current, marker);
else wrap(() => current = insertExpression(parent, rendered(), current, marker));
addNode(parent, fallback(), marker, ++groupCounter, node => current = node);
});
}
return index;
} else {
root(disposer => {
disposable = disposer;
addNode(parent, render(), marker, ++groupCounter, node => current = node, afterRender && afterRender(node, marker));
});
}
root(disposer => {
disposable = disposer;
const rendered = render();
if (typeof rendered !== 'function') current = insertExpression(parent, rendered, current, marker);
else wrap(() => current = insertExpression(parent, rendered(), current, marker));
});
afterRender && afterRender(current, marker);
return index;
});
});
Expand Down Expand Up @@ -658,10 +648,8 @@ export function suspend(parent, accessor, expr, options, marker) {
let node;
parent = (marker && marker.parentNode) || (beforeNode && beforeNode.parentNode) || parent;
if (value) {
if (options.initializing) {
if (typeof rendered !== 'function') insertExpression(doc.body, rendered);
else wrap(() => insertExpression(doc.body, rendered()));
} else {
if (options.initializing) addNode(doc.body, rendered, undefined, ++groupCounter);
else {
node = marker !== undefined ? step(marker.previousSibling, BACKWARD, true) : parent.firstChild;
while (node && node !== marker) {
const next = node.nextSibling;
Expand All @@ -672,17 +660,13 @@ export function suspend(parent, accessor, expr, options, marker) {
if (fallback) {
sample(() => root(disposer => {
disposable = disposer;
const rendered = fallback();
if (typeof rendered !== 'function') current = insertExpression(parent, rendered, current, marker);
else wrap(() => current = insertExpression(parent, rendered(), current, marker));
addNode(parent, fallback(), marker, ++groupCounter, node => current = node);
}));
}
return value;
}
if (options.initializing) {
if (typeof rendered !== 'function') current = insertExpression(parent, rendered, undefined, marker);
else wrap(() => current = insertExpression(parent, rendered(), undefined, marker));
} else {
if (options.initializing) addNode(parent, rendered, marker, ++groupCounter, node => current = node);
else {
if (disposable) {
clearAll(parent, current, marker, beforeNode && beforeNode.nextSibling);
disposable();
Expand Down Expand Up @@ -711,9 +695,7 @@ export function provide(parent, accessor, expr, options, marker) {
wrap(() => {
sample(() => {
setContext(Context.id, Context.initFn ? Context.initFn(value) : value);
const rendered = expr();
if (typeof rendered !== 'function') insertExpression(parent, rendered, undefined, marker);
else wrap(() => insertExpression(parent, rendered(), undefined, marker));
addNode(parent, expr(), marker, ++groupCounter);
});
});
}
Expand All @@ -727,10 +709,7 @@ export function portal(parent, accessor, expr, options, marker) {
if (marker !== undefined) beforeNode = marker ? marker.previousSibling : parent.lastChild;
Object.defineProperty(container, 'host', { get() { return (marker && marker.parentNode) || (beforeNode && beforeNode.parentNode) || parent; } });
const nodes = sample(() => expr(container));
if (typeof nodes !== 'function') insertExpression(container, nodes);
else wrap(() => insertExpression(container, nodes()));
// ShadyDOM polyfill doesn't handle mutationObserver on shadowRoot properly
if (container !== renderRoot) Promise.resolve().then(() => { while(container.firstChild) renderRoot.appendChild(container.firstChild); });
addNode(renderRoot, nodes, undefined, ++groupCounter);
anchor.appendChild(container);
cleanup(() => anchor.removeChild(container));
}

0 comments on commit 4c1eb15

Please sign in to comment.