Add prepare functionality to the TemplateRendererProxy shim (#1775)

This commit is contained in:
toasted-nutbread 2021-06-27 20:30:37 -04:00 committed by GitHub
parent 1794c94844
commit af706dea7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -56,8 +56,9 @@ async function createVM() {
const ankiNoteDataCreator = vm.ankiNoteDataCreator; const ankiNoteDataCreator = vm.ankiNoteDataCreator;
class TemplateRendererProxy { class TemplateRendererProxy {
constructor() { constructor() {
const japaneseUtil = new JapaneseUtil(null); this._preparePromise = null;
this._templateRenderer = new TemplateRenderer(japaneseUtil); this._japaneseUtil = new JapaneseUtil(null);
this._templateRenderer = new TemplateRenderer(this._japaneseUtil);
this._templateRenderer.registerDataType('ankiNote', { this._templateRenderer.registerDataType('ankiNote', {
modifier: ({marker, commonData}) => ankiNoteDataCreator.create(marker, commonData), modifier: ({marker, commonData}) => ankiNoteDataCreator.create(marker, commonData),
composeData: (marker, commonData) => ({marker, commonData}) composeData: (marker, commonData) => ({marker, commonData})
@ -65,11 +66,24 @@ async function createVM() {
} }
async render(template, data, type) { 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) { 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) { _serializeError(error) {