1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Emit an error on async fromStore (#3285)

This commit is contained in:
Sebastian Malton 2021-07-06 11:05:07 -04:00 committed by GitHub
parent 803c3a3d34
commit 0f9f79a8c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 5 deletions

View File

@ -56,9 +56,15 @@ export abstract class BaseStore<T> extends Singleton {
cwd: this.cwd(), cwd: this.cwd(),
}); });
logger.info(`[STORE]: LOADED from ${this.path}`); const res: any = this.fromStore(this.storeConfig.store);
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(); this.enableSync();
logger.info(`[STORE]: LOADED from ${this.path}`);
} }
get name() { 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 * fromStore is called internally when a child class syncs with the file
* system. * system.
*
* Note: This function **must** be synchronous.
*
* @param data the parsed information read from the stored JSON file * @param data the parsed information read from the stored JSON file
*/ */
protected abstract fromStore(data: T): void; protected abstract fromStore(data: T): void;

View File

@ -94,7 +94,7 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
} }
@action @action
protected async fromStore(data: Partial<HotbarStoreModel> = {}) { protected fromStore(data: Partial<HotbarStoreModel> = {}) {
if (!data.hotbars || !data.hotbars.length) { if (!data.hotbars || !data.hotbars.length) {
this.hotbars = [{ this.hotbars = [{
id: uuid.v4(), id: uuid.v4(),

View File

@ -155,7 +155,7 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
} }
@action @action
protected async fromStore(data: Partial<UserStoreModel> = {}) { protected fromStore(data: Partial<UserStoreModel> = {}) {
const { lastSeenAppVersion, preferences } = data; const { lastSeenAppVersion, preferences } = data;
if (lastSeenAppVersion) { if (lastSeenAppVersion) {

View File

@ -58,7 +58,8 @@ export class WeblinkStore extends BaseStore<WeblinkStoreModel> {
this.load(); this.load();
} }
@action protected async fromStore(data: Partial<WeblinkStoreModel> = {}) { @action
protected fromStore(data: Partial<WeblinkStoreModel> = {}) {
this.weblinks = data.weblinks || []; this.weblinks = data.weblinks || [];
} }