summaryrefslogtreecommitdiff
path: root/test/test-anki-note-builder.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-06-27 20:30:37 -0400
committerGitHub <noreply@github.com>2021-06-27 20:30:37 -0400
commitaf706dea7e25ae42a7e032a2275d69d3211a98e3 (patch)
tree52d9f2a19afa063e4707a97d6541812c5558a320 /test/test-anki-note-builder.js
parent1794c948449c474ccf0cce53d2a4555723d0c11b (diff)
Add prepare functionality to the TemplateRendererProxy shim (#1775)
Diffstat (limited to 'test/test-anki-note-builder.js')
-rw-r--r--test/test-anki-note-builder.js22
1 files 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) {