Merge pull request #13286 from supabase/fix/update-is-initialized-logic-in-postgresmetainterface

Fix is initialized logic in postgresmeta interace
This commit is contained in:
Joshen Lim authored and GitHub committed 2023-03-29 15:58:12 +08:00
commit b5ebfca0ae
1 file changed
+3 -4
@@ -47,6 +47,7 @@ export default class PostgresMetaInterface<T> implements IPostgresMetaInterface<
state = this.STATES.INITIAL
data: { [key in DataKeys]: T } = {}
headers: any = {}
isInitialized: boolean = false
constructor(
rootStore: IRootStore,
@@ -90,10 +91,6 @@ export default class PostgresMetaInterface<T> implements IPostgresMetaInterface<
return this.state === this.STATES.INITIAL || this.state === this.STATES.LOADING
}
get isInitialized() {
return this.state === this.STATES.LOADED || this.state === this.STATES.ERROR
}
async fetchData() {
const headers = { 'Content-Type': 'application/json', ...this.headers }
const response = await get<T[]>(this.url, { headers })
@@ -114,6 +111,8 @@ export default class PostgresMetaInterface<T> implements IPostgresMetaInterface<
console.error('Load error message', e.message)
this.setError(e)
this.setState(ERROR)
} finally {
if (!this.isInitialized) this.isInitialized = true
}
}