summaryrefslogtreecommitdiff
path: root/test/test-anki-note-builder.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-04-02 19:09:21 -0400
committerGitHub <noreply@github.com>2021-04-02 19:09:21 -0400
commitdabda86259d78ee66125ebf2cff15a7619e0b5da (patch)
tree721043546abc01d5c5a2d17f2f2abd8e34ce2a53 /test/test-anki-note-builder.js
parent28fa3fa795d564135940e8aff52b987a5960f15c (diff)
Optimize template renderer (#1585)
* Add renderMulti * Batch template rendering * Update tests
Diffstat (limited to 'test/test-anki-note-builder.js')
-rw-r--r--test/test-anki-note-builder.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/test/test-anki-note-builder.js b/test/test-anki-note-builder.js
index b1fffbcd..152a8739 100644
--- a/test/test-anki-note-builder.js
+++ b/test/test-anki-note-builder.js
@@ -55,12 +55,28 @@ async function createVM() {
const japaneseUtil = new JapaneseUtil(null);
this._templateRenderer = new TemplateRenderer(japaneseUtil);
this._templateRenderer.registerDataType('ankiNote', {
- modifier: ({marker, commonData}) => ankiNoteDataCreator.create(marker, commonData)
+ modifier: ({marker, commonData}) => ankiNoteDataCreator.create(marker, commonData),
+ composeData: (marker, commonData) => ({marker, commonData})
});
}
async render(template, data, type) {
- return await this._templateRenderer.render(template, data, type);
+ return this._templateRenderer.render(template, data, type);
+ }
+
+ async renderMulti(items) {
+ return this._serializeMulti(this._templateRenderer.renderMulti(items));
+ }
+
+ _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;
}
}
vm.set({TemplateRendererProxy});