various widget refactorings

This commit is contained in:
zadam
2020-02-02 21:16:20 +01:00
parent 7c6cd63a53
commit d5ae3802d1
10 changed files with 50 additions and 114 deletions

View File

@@ -2,11 +2,10 @@ import server from "./server.js";
import bundleService from "./bundle.js";
async function render(note, $el, ctx) {
const attributes = await note.getAttributes();
const renderNoteIds = attributes.filter(attr =>
attr.type === 'relation'
&& attr.name === 'renderNote'
&& !!attr.value).map(rel => rel.value);
const relations = await note.getRelations('renderNote');
const renderNoteIds = relations
.map(rel => rel.value)
.filter(noteId => noteId);
$el.empty().toggle(renderNoteIds.length > 0);
@@ -18,11 +17,8 @@ async function render(note, $el, ctx) {
$scriptContainer.append(bundle.html);
const $result = await bundleService.executeBundle(bundle, note, ctx, $scriptContainer);
if ($result) {
$scriptContainer.append($result);
}
// async so that scripts cannot block trilium execution
bundleService.executeBundle(bundle, note, ctx, $scriptContainer);
}
return renderNoteIds.length > 0;