Skip to content

Commit

Permalink
npf.js: use DocumentFragment instead of Element[]
Browse files Browse the repository at this point in the history
  • Loading branch information
AprilSylph committed Nov 5, 2021
1 parent f71d256 commit 63be7f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/lib/npf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const keyBy = (array, input) => array.reduce((accumulator, currentValue) => Obje
Object.prototype.tap = function(f) { f(this); return this; };

export const renderContent = ({ content: blocks, layout }) => {
const content = [];
const content = new DocumentFragment();
const { rows, ask } = keyBy(layout, 'type');
const { truncate_after } = rows || {};

Expand All @@ -31,16 +31,16 @@ export const renderContent = ({ content: blocks, layout }) => {

normalizeRows(rows, blocks).forEach(row => {
if (ask && row.blocks.find(i => ask.blocks.includes(i)) !== undefined) {
askContent = askContent || [];
askContent.push(...renderRow(row));
askContent = askContent || new DocumentFragment();
askContent.append(...renderRow(row));
} else if (row.blocks.find(i => i > truncate_after) !== undefined) {
details = details || document.createElement('details').tap(d => {
d.append(document.createElement('summary').tap(s => s.textContent = 'Keep reading'));
content.push(d);
content.append(d);
});
details.append(...renderRow(row));
} else {
content.push(...renderRow(row));
content.append(...renderRow(row));
}
});

Expand Down
8 changes: 3 additions & 5 deletions src/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,12 @@ const constructItem = ([timestamp, { recipient, recipientUrl, content, layout }]
}));
}

askElement.append(...ask.content);
askElement.append(ask.content);
buildLists(askElement);
}

if (renderedContent) {
bodyElement.append(...renderedContent);
buildLists(bodyElement);
}
bodyElement.append(renderedContent);
buildLists(bodyElement);

const footerElement = document.createElement('footer');
articleElement.appendChild(footerElement);
Expand Down

0 comments on commit 63be7f8

Please sign in to comment.