summaryrefslogtreecommitdiff
path: root/ext/js/templates/__mocks__
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-12-06 03:53:16 +0000
committerGitHub <noreply@github.com>2023-12-06 03:53:16 +0000
commitbd5bc1a5db29903bc098995cd9262c4576bf76af (patch)
treec9214189e0214480fcf6539ad1c6327aef6cbd1c /ext/js/templates/__mocks__
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
parent23e6fb76319c9ed7c9bcdc3efba39bc5dd38f288 (diff)
Merge pull request #339 from toasted-nutbread/type-annotations
Type annotations
Diffstat (limited to 'ext/js/templates/__mocks__')
-rw-r--r--ext/js/templates/__mocks__/template-renderer-proxy.js53
1 files changed, 18 insertions, 35 deletions
diff --git a/ext/js/templates/__mocks__/template-renderer-proxy.js b/ext/js/templates/__mocks__/template-renderer-proxy.js
index bcacf13b..8823e8f3 100644
--- a/ext/js/templates/__mocks__/template-renderer-proxy.js
+++ b/ext/js/templates/__mocks__/template-renderer-proxy.js
@@ -20,20 +20,35 @@ import {AnkiTemplateRenderer} from '../sandbox/anki-template-renderer.js';
export class TemplateRendererProxy {
constructor() {
+ /** @type {?Promise<void>} */
this._preparePromise = null;
+ /** @type {AnkiTemplateRenderer} */
this._ankiTemplateRenderer = new AnkiTemplateRenderer();
}
+ /**
+ * @param {string} template
+ * @param {import('template-renderer').PartialOrCompositeRenderData} data
+ * @param {import('anki-templates').RenderMode} type
+ * @returns {Promise<import('template-renderer').RenderResult>}
+ */
async render(template, data, type) {
await this._prepare();
- return await this._ankiTemplateRenderer.templateRenderer.render(template, data, type);
+ return this._ankiTemplateRenderer.templateRenderer.render(template, data, type);
}
+ /**
+ * @param {import('template-renderer').RenderMultiItem[]} items
+ * @returns {Promise<import('core').Response<import('template-renderer').RenderResult>[]>}
+ */
async renderMulti(items) {
await this._prepare();
- return await this._serializeMulti(this._ankiTemplateRenderer.templateRenderer.renderMulti(items));
+ return this._ankiTemplateRenderer.templateRenderer.renderMulti(items);
}
+ /**
+ * @returns {Promise<void>}
+ */
_prepare() {
if (this._preparePromise === null) {
this._preparePromise = this._prepareInternal();
@@ -41,40 +56,8 @@ export class TemplateRendererProxy {
return this._preparePromise;
}
+ /** */
async _prepareInternal() {
await this._ankiTemplateRenderer.prepare();
}
-
- _serializeError(error) {
- try {
- if (typeof error === 'object' && error !== null) {
- const result = {
- name: error.name,
- message: error.message,
- stack: error.stack
- };
- if (Object.prototype.hasOwnProperty.call(error, 'data')) {
- result.data = error.data;
- }
- return result;
- }
- } catch (e) {
- // NOP
- }
- return {
- value: error,
- hasValue: true
- };
- }
-
- _serializeMulti(array) {
- for (let i = 0, ii = array.length; i < ii; ++i) {
- const value = array[i];
- const {error} = value;
- if (typeof error !== 'undefined') {
- value.error = this._serializeError(error);
- }
- }
- return array;
- }
}