Emit an error on async fromStore (#3285)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-07-06 11:05:07 -04:00
1 parent 803c3a3d34
commit 0f9f79a8c9
4 files changed
+15 -5

No files matched your search

+11 -2
View File
@@ -56,9 +56,15 @@ export abstract class BaseStore<T> extends Singleton {
cwd: this.cwd(),
});
logger.info(`[STORE]: LOADED from ${this.path}`);
this.fromStore(this.storeConfig.store);
const res: any = this.fromStore(this.storeConfig.store);
if (res instanceof Promise || (typeof res === "object" && res && typeof res.then === "function")) {
console.error(`${this.name} extends BaseStore<T>'s fromStore method returns a Promise or promise-like object. This is an error and must be fixed.`);
}
this.enableSync();
logger.info(`[STORE]: LOADED from ${this.path}`);
}
get name() {
@@ -157,6 +163,9 @@ export abstract class BaseStore<T> extends Singleton {
/**
* fromStore is called internally when a child class syncs with the file
* system.
*
* Note: This function **must** be synchronous.
*
* @param data the parsed information read from the stored JSON file
*/
protected abstract fromStore(data: T): void;
+1 -1
View File
@@ -94,7 +94,7 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
}
@action
protected async fromStore(data: Partial<HotbarStoreModel> = {}) {
protected fromStore(data: Partial<HotbarStoreModel> = {}) {
if (!data.hotbars || !data.hotbars.length) {
this.hotbars = [{
id: uuid.v4(),
+1 -1
View File
@@ -155,7 +155,7 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
}
@action
protected async fromStore(data: Partial<UserStoreModel> = {}) {
protected fromStore(data: Partial<UserStoreModel> = {}) {
const { lastSeenAppVersion, preferences } = data;
if (lastSeenAppVersion) {
+2 -1
View File
@@ -58,7 +58,8 @@ export class WeblinkStore extends BaseStore<WeblinkStoreModel> {
this.load();
}
@action protected async fromStore(data: Partial<WeblinkStoreModel> = {}) {
@action
protected fromStore(data: Partial<WeblinkStoreModel> = {}) {
this.weblinks = data.weblinks || [];
}