mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 12:26:01 +00:00
fixed race conditions when starting app
This commit is contained in:
22
packages/web/src/utility/appLoadManager.ts
Normal file
22
packages/web/src/utility/appLoadManager.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
let appIsLoaded = false;
|
||||
let onLoad = [];
|
||||
|
||||
export function setAppLoaded() {
|
||||
appIsLoaded = true;
|
||||
for (const func of onLoad) {
|
||||
func();
|
||||
}
|
||||
onLoad = [];
|
||||
}
|
||||
|
||||
export function getAppLoaded() {
|
||||
return appIsLoaded;
|
||||
}
|
||||
|
||||
export function callWhenAppLoaded(callback) {
|
||||
if (appIsLoaded) {
|
||||
callback();
|
||||
} else {
|
||||
onLoad.push(callback);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
import _ from 'lodash';
|
||||
import { currentDatabase, openedTabs } from '../stores';
|
||||
import { callWhenAppLoaded } from './appLoadManager';
|
||||
import { getConnectionInfo } from './metadataLoaders';
|
||||
|
||||
let lastCurrentTab = null;
|
||||
|
||||
openedTabs.subscribe(async value => {
|
||||
openedTabs.subscribe(value => {
|
||||
const newCurrentTab = (value || []).find(x => x.selected);
|
||||
if (newCurrentTab == lastCurrentTab) return;
|
||||
|
||||
@@ -15,11 +16,14 @@ openedTabs.subscribe(async value => {
|
||||
database &&
|
||||
(conid != _.get(lastCurrentTab, 'props.conid') || database != _.get(lastCurrentTab, 'props.database'))
|
||||
) {
|
||||
const connection = await getConnectionInfo({ conid });
|
||||
currentDatabase.set({
|
||||
connection,
|
||||
name: database,
|
||||
});
|
||||
const doWork = async () => {
|
||||
const connection = await getConnectionInfo({ conid });
|
||||
currentDatabase.set({
|
||||
connection,
|
||||
name: database,
|
||||
});
|
||||
};
|
||||
callWhenAppLoaded(doWork);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user