packages/core-api: make App configLoader optional and synchronous when missing

This commit is contained in:
Patrik Oldsberg
2020-06-01 14:58:52 +02:00
parent 44f61015f5
commit 65ab1685f4
2 changed files with 6 additions and 5 deletions
+6 -4
View File
@@ -43,7 +43,7 @@ type FullAppOptions = {
plugins: BackstagePlugin[];
components: AppComponents;
themes: AppTheme[];
configLoader: AppConfigLoader;
configLoader?: AppConfigLoader;
};
export class PrivateAppImpl implements BackstageApp {
@@ -52,7 +52,7 @@ export class PrivateAppImpl implements BackstageApp {
private readonly plugins: BackstagePlugin[];
private readonly components: AppComponents;
private readonly themes: AppTheme[];
private readonly configLoader: AppConfigLoader;
private readonly configLoader?: AppConfigLoader;
constructor(options: FullAppOptions) {
this.apis = options.apis;
@@ -148,11 +148,13 @@ export class PrivateAppImpl implements BackstageApp {
getProvider(): ComponentType<{}> {
const Provider: FC<{}> = ({ children }) => {
const config = useAsync(this.configLoader);
// Keeping this synchronous when a config loader isn't set simplifies tests a lot
const hasConfig = Boolean(this.configLoader);
const config = useAsync(this.configLoader || (() => Promise.resolve({})));
let childNode = children;
if (config.loading) {
if (hasConfig && config.loading) {
const { Progress } = this.components;
childNode = <Progress />;
} else if (config.error) {
@@ -66,7 +66,6 @@ export function wrapInTestApp(
variant: 'light',
},
],
configLoader: async () => ({}),
});
let Wrapper: ComponentType;