aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/api.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-09-05 20:35:39 -0700
committerAlex Yatskov <alex@foosoft.net>2017-09-05 20:35:39 -0700
commit722ddf163818035d603ba8042e1e32ff7dcdfc84 (patch)
tree1fd4ed0766b2b4ea19ac6eb9224bb5d66edde859 /ext/bg/js/api.js
parent9eac50ea05ae48e77c1bb0ef7b42d9662094cbf8 (diff)
work on sandbox
Diffstat (limited to 'ext/bg/js/api.js')
-rw-r--r--ext/bg/js/api.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index 96147d95..aba1b722 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -100,6 +100,23 @@ 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 apiCommandExec(command) {
const handlers = {
search: () => {