From af706dea7e25ae42a7e032a2275d69d3211a98e3 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 27 Jun 2021 20:30:37 -0400 Subject: Add prepare functionality to the TemplateRendererProxy shim (#1775) --- test/test-anki-note-builder.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/test/test-anki-note-builder.js b/test/test-anki-note-builder.js index d3ea0b6a..d7045254 100644 --- a/test/test-anki-note-builder.js +++ b/test/test-anki-note-builder.js @@ -56,8 +56,9 @@ async function createVM() { const ankiNoteDataCreator = vm.ankiNoteDataCreator; class TemplateRendererProxy { constructor() { - const japaneseUtil = new JapaneseUtil(null); - this._templateRenderer = new TemplateRenderer(japaneseUtil); + this._preparePromise = null; + this._japaneseUtil = new JapaneseUtil(null); + this._templateRenderer = new TemplateRenderer(this._japaneseUtil); this._templateRenderer.registerDataType('ankiNote', { modifier: ({marker, commonData}) => ankiNoteDataCreator.create(marker, commonData), composeData: (marker, commonData) => ({marker, commonData}) @@ -65,11 +66,24 @@ async function createVM() { } async render(template, data, type) { - return this._templateRenderer.render(template, data, type); + await this._prepare(); + return await this._templateRenderer.render(template, data, type); } async renderMulti(items) { - return this._serializeMulti(this._templateRenderer.renderMulti(items)); + await this._prepare(); + return await this._serializeMulti(this._templateRenderer.renderMulti(items)); + } + + _prepare() { + if (this._preparePromise === null) { + this._preparePromise = this._prepareInternal(); + } + return this._preparePromise; + } + + async _prepareInternal() { + // Empty } _serializeError(error) { -- cgit v1.2.3