From 083999212e262c0a51b9401cb9666e6a49e35de9 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 5 Sep 2017 21:10:19 -0700 Subject: work on sandbox --- ext/bg/js/api.js | 38 +++++++++++++++++++------------------- ext/bg/js/backend.js | 4 ++-- 2 files changed, 21 insertions(+), 21 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index aba1b722..0aad436a 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -96,25 +96,25 @@ async function apiNoteView(noteId) { return utilBackend().anki.guiBrowse(`nid:${noteId}`); } -async function apiTemplateRender(template, data) { - return handlebarsRender(template, data); -} - -async function apiTemplateRenderDynamic(template, data) { - return new Promise((resolve, reject) => { - const sequence = utilBackend().sequenceNew(); - const handler = event => { - if (event.data.sequence === sequence) { - resolve(event.data.result); - window.removeEventListener('message', handler); - } - }; - - window.addEventListener('message', handler); - - const sandbox = utilBackend().sandbox(); - sandbox.postMessage({template, data, sequence, command: 'render'}, '*'); - }); +async function apiTemplateRender(template, data, dynamic) { + if (dynamic) { + return new Promise((resolve, reject) => { + const sequence = utilBackend().sequenceNew(); + const handler = event => { + if (event.data.sequence === sequence) { + resolve(event.data.result); + window.removeEventListener('message', handler); + } + }; + + window.addEventListener('message', handler); + + const sandbox = utilBackend().sandbox(); + sandbox.postMessage({template, data, sequence, command: 'render'}, '*'); + }); + } else { + return handlebarsRender(template, data); + } } async function apiCommandExec(command) { diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 9802ea7c..5061557b 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -113,8 +113,8 @@ class Backend { forward(apiNoteView(noteId), callback); }, - templateRender: ({template, data, callback}) => { - forward(apiTemplateRender(template, data), callback); + templateRender: ({template, data, dynamic, callback}) => { + forward(apiTemplateRender(template, data, dynamic), callback); }, commandExec: ({command, callback}) => { -- cgit v1.2.3