From 4fcff3e06e140a09938ecb1c22dcc27925dc198d Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 18 Jan 2026 23:22:34 -0700 Subject: [PATCH] Pull out the document into a protected property so that it can be called by subclasses --- module/apps/mixins/DBConnector.mjs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/module/apps/mixins/DBConnector.mjs b/module/apps/mixins/DBConnector.mjs index 3167fe8..660a178 100644 --- a/module/apps/mixins/DBConnector.mjs +++ b/module/apps/mixins/DBConnector.mjs @@ -43,6 +43,21 @@ export function DBConnectorMixin(HandlebarsApp) { return super.render(options, ...args); }; + async _fetchDocument() { + if (!this._docID) { return } + const documents = await getFile(this.dbPath); + + if (documents[this._docID] == null) { + ui.notifications.error(_loc( + `TB.notifs.error.document-ID-404`, + { id: this._docID, dbType: this.dbType }, + )); + return false; + }; + + Object.assign(this._doc, documents[this._docID]); + }; + /** * This fetches the DB data that we care about for the purposes of being able * to create/edit entries in the Artists DB @@ -50,20 +65,7 @@ export function DBConnectorMixin(HandlebarsApp) { async #connectToDB() { if (this.#connected) { return true }; this.#lastModified ??= await lastModifiedAt(this.dbPath); - - if (this._docID) { - const documents = await getFile(this.dbPath); - - if (documents[this._docID] == null) { - ui.notifications.error(_loc( - `TB.notifs.error.document-ID-404`, - { id: this._docID, dbType: this.dbType }, - )); - return false; - }; - - Object.assign(this._doc, documents[this._docID]); - }; + this._fetchDocument() this.#connected = true; return true; };