summaryrefslogtreecommitdiff
path: root/ext/js/templates/template-renderer-frame-api.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-04-02 12:42:06 -0400
committerGitHub <noreply@github.com>2021-04-02 12:42:06 -0400
commit8179846e381eb0a87bf3bc266abec8f4400565bc (patch)
treeddb57d7870b461c9758f6de8a25dd76bbfaf81f7 /ext/js/templates/template-renderer-frame-api.js
parent36b7e34cce776cb09a76c28ce8e78e864dabcdda (diff)
Refactor template rendering (#1583)
* Update _errorToJson to _serializeError * Remove async * Refactor render * Simplify _getModifiedData * Rename data => commonData * Rename templates => template for consistency * Improve errors check * Update tests
Diffstat (limited to 'ext/js/templates/template-renderer-frame-api.js')
-rw-r--r--ext/js/templates/template-renderer-frame-api.js18
1 files changed, 9 insertions, 9 deletions
diff --git a/ext/js/templates/template-renderer-frame-api.js b/ext/js/templates/template-renderer-frame-api.js
index 6eebc199..104e357b 100644
--- a/ext/js/templates/template-renderer-frame-api.js
+++ b/ext/js/templates/template-renderer-frame-api.js
@@ -19,8 +19,8 @@ class TemplateRendererFrameApi {
constructor(templateRenderer) {
this._templateRenderer = templateRenderer;
this._windowMessageHandlers = new Map([
- ['render', {async: true, handler: this._onRender.bind(this)}],
- ['getModifiedData', {async: true, handler: this._onGetModifiedData.bind(this)}]
+ ['render', {async: false, handler: this._onRender.bind(this)}],
+ ['getModifiedData', {async: false, handler: this._onGetModifiedData.bind(this)}]
]);
}
@@ -47,25 +47,25 @@ class TemplateRendererFrameApi {
}
response = {result};
} catch (error) {
- response = {error: this._errorToJson(error)};
+ response = {error: this._serializeError(error)};
}
if (typeof id === 'undefined') { return; }
source.postMessage({action: `${action}.response`, params: response, id}, '*');
}
- async _onRender({template, data, type}) {
- return await this._templateRenderer.render(template, data, type);
+ _onRender({template, data, type}) {
+ return this._templateRenderer.render(template, data, type);
}
- async _onGetModifiedData({data, type}) {
- const result = await this._templateRenderer.getModifiedData(data, type);
+ _onGetModifiedData({data, type}) {
+ const result = this._templateRenderer.getModifiedData(data, type);
return this._clone(result);
}
- _errorToJson(error) {
+ _serializeError(error) {
try {
- if (error !== null && typeof error === 'object') {
+ if (typeof error === 'object' && error !== null) {
return {
name: error.name,
message: error.message,