Skip to content

Commit

Permalink
fix(platform): remove ES2015 import cycles
Browse files Browse the repository at this point in the history
closes #42
  • Loading branch information
mofogasy committed Mar 26, 2021
1 parent 6f7ac15 commit 879836d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { Logger } from '../../logger';
import { PlatformMessageClient } from '../platform-message-client';
import { MessageHeaders } from '../../messaging.model';
import { EMPTY } from 'rxjs';
import { MicrofrontendPlatform } from '../../microfrontend-platform';
import { PlatformState } from '../../platform-state';
import { Beans, Initializer } from '@scion/toolkit/bean-manager';
import { PlatformStateRef } from '../../platform-state-ref';

/**
* Activates micro applications which provide an activator capability.
Expand Down Expand Up @@ -119,7 +119,7 @@ export class ActivatorInstaller implements Initializer {
// Add the router outlet to the DOM
document.body.appendChild(routerOutlet);
// Unmount the router outlet on platform shutdown
MicrofrontendPlatform.whenState(PlatformState.Stopped).then(() => document.body.removeChild(routerOutlet));
Beans.get(PlatformStateRef).whenState(PlatformState.Stopped).then(() => document.body.removeChild(routerOutlet));
}
}

Expand Down
1 change: 0 additions & 1 deletion projects/scion/microfrontend-platform/src/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export abstract class Logger {
*
* Replace this bean to capture the log output.
*
* @ignore
* @internal
*/
export class ConsoleLogger implements Logger {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { PlatformState, Runlevel } from './platform-state';
import { AbstractType, BeanInstanceConstructInstructions, Beans, Type } from '@scion/toolkit/bean-manager';
import { ɵIntentClient } from './client/messaging/ɵintent-client';
import { ɵMessageClient } from './client/messaging/ɵmessage-client';
import { PlatformStateRef } from './platform-state-ref';

window.addEventListener('beforeunload', () => MicrofrontendPlatform.destroy(), {once: true});

Expand Down Expand Up @@ -102,7 +103,7 @@ window.addEventListener('beforeunload', () => MicrofrontendPlatform.destroy(), {
*
* @category Platform
*/
// @dynamic `ng-packagr` does not support lamdas in statics if `strictMetaDataEmit` is enabled. `ng-packagr` is used to build this library. See https://github.com/ng-packagr/ng-packagr/issues/696#issuecomment-373487183.
// @dynamic `ng-packagr` does not support lambdas in statics if `strictMetaDataEmit` is enabled. `ng-packagr` is used to build this library. See https://github.com/ng-packagr/ng-packagr/issues/696#issuecomment-373487183.
export class MicrofrontendPlatform {

private static _state$ = new BehaviorSubject<PlatformState>(PlatformState.Stopped);
Expand Down Expand Up @@ -181,6 +182,7 @@ export class MicrofrontendPlatform {
Beans.registerIfAbsent(OutletRouter);
Beans.registerIfAbsent(RelativePathResolver);
Beans.registerIfAbsent(RouterOutletUrlAssigner);
Beans.register(PlatformStateRef, {useValue: MicrofrontendPlatform});

Beans.register(ɵPlatformBrokerGatewaySymbol, provideBrokerGateway(PLATFORM_SYMBOLIC_NAME, hostAppConfig && hostAppConfig.messaging));
Beans.registerIfAbsent(PlatformMessageClient, provideMessageClient(ɵPlatformBrokerGatewaySymbol));
Expand Down Expand Up @@ -266,6 +268,7 @@ export class MicrofrontendPlatform {
Beans.register(ContextService);
Beans.register(ManifestService);
Beans.register(KeyboardEventDispatcher, {eager: true});
Beans.register(PlatformStateRef, {useValue: MicrofrontendPlatform});
},
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2018-2020 Swiss Federal Railways
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/

import { PlatformState } from './platform-state';

/**
* Provides access to the platform state.
*
* Use this bean from within a class which is itself referenced in the MicrofrontendPlatform, in order to avoid ES2015 import cycles.
*
* @see {@link ActivatorInstaller} for an example.
* @ignore
*/
export abstract class PlatformStateRef {

public abstract whenState(state: PlatformState): Promise<void>;
}

0 comments on commit 879836d

Please sign in to comment.