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:
parent
803c3a3d34
commit
0f9f79a8c9
@ -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;
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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 || [];
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user