work on sandbox

This commit is contained in:
Alex Yatskov 2017-09-05 21:10:19 -07:00
parent 722ddf1638
commit 083999212e
3 changed files with 21 additions and 21 deletions

View File

@ -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 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);
}
};
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);
window.addEventListener('message', handler);
const sandbox = utilBackend().sandbox();
sandbox.postMessage({template, data, sequence, command: 'render'}, '*');
});
const sandbox = utilBackend().sandbox();
sandbox.postMessage({template, data, sequence, command: 'render'}, '*');
});
} else {
return handlebarsRender(template, data);
}
}
async function apiCommandExec(command) {

View File

@ -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}) => {

View File

@ -45,8 +45,8 @@ function apiNoteView(noteId) {
return utilInvoke('noteView', {noteId});
}
function apiTemplateRender(template, data) {
return utilInvoke('templateRender', {data, template});
function apiTemplateRender(template, data, dynamic) {
return utilInvoke('templateRender', {data, template, dynamic});
}
function apiCommandExec(command) {