diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-07-03 11:30:48 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-03 11:30:48 -0400 |
commit | f7d177e6d0f970ba6600fbf3911fccc093553eef (patch) | |
tree | d83865cb66308f98b57bea7d9e1ca172c257e049 /ext/js/data | |
parent | d7c934cae8c4f0747a0298b7e237ebab4efd48e5 (diff) |
Refactor createNote (#1789)
* Update createNote to return a wrapper object
* Update how createNote creates errors
Diffstat (limited to 'ext/js/data')
-rw-r--r-- | ext/js/data/anki-note-builder.js | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/ext/js/data/anki-note-builder.js b/ext/js/data/anki-note-builder.js index c36ad889..4427c276 100644 --- a/ext/js/data/anki-note-builder.js +++ b/ext/js/data/anki-note-builder.js @@ -42,8 +42,7 @@ class AnkiNoteBuilder { duplicateScope='collection', resultOutputMode='split', glossaryLayoutMode='default', - compactTags=false, - errors=null + compactTags=false }) { let duplicateScopeDeckName = null; let duplicateScopeCheckChildren = false; @@ -53,6 +52,7 @@ class AnkiNoteBuilder { duplicateScopeCheckChildren = true; } + const errors = []; const commonData = this._createData(dictionaryEntry, mode, context, resultOutputMode, glossaryLayoutMode, compactTags, injectedMedia); const formattedFieldValuePromises = []; for (const [, fieldValue] of fields) { @@ -68,7 +68,7 @@ class AnkiNoteBuilder { noteFields[fieldName] = formattedFieldValue; } - return { + const note = { fields: noteFields, tags, deckName, @@ -82,6 +82,7 @@ class AnkiNoteBuilder { } } }; + return {note, errors}; } async getRenderingData({ @@ -112,17 +113,15 @@ class AnkiNoteBuilder { }; } - async _formatField(field, commonData, template, errors=null) { + async _formatField(field, commonData, template, errors) { return await this._stringReplaceAsync(field, this._markerPattern, async (g0, marker) => { try { const {result} = await this._renderTemplateBatched(template, commonData, marker); return result; } catch (e) { - if (Array.isArray(errors)) { - const error = new Error(`Template render error for {${marker}}`); - error.data = {error: e}; - errors.push(error); - } + const error = new Error(`Template render error for {${marker}}`); + error.data = {error: e}; + errors.push(error); return `{${marker}-render-error}`; } }); |