fix(platform-server): allow multiple instances of platformServer and platformDynamicServer
This commit is contained in:

committed by
Igor Minar

parent
0e2fd9d91a
commit
17486fd696
@ -37,6 +37,8 @@ let _devMode: boolean = true;
|
||||
let _runModeLocked: boolean = false;
|
||||
let _platform: PlatformRef;
|
||||
|
||||
export const ALLOW_MULTIPLE_PLATFORMS = new InjectionToken<boolean>('AllowMultipleToken');
|
||||
|
||||
/**
|
||||
* Disable Angular's development mode, which turns off assertions and other
|
||||
* checks within the framework.
|
||||
@ -83,7 +85,8 @@ export class NgProbeToken {
|
||||
* @experimental APIs related to application bootstrap are currently under review.
|
||||
*/
|
||||
export function createPlatform(injector: Injector): PlatformRef {
|
||||
if (_platform && !_platform.destroyed) {
|
||||
if (_platform && !_platform.destroyed &&
|
||||
!_platform.injector.get(ALLOW_MULTIPLE_PLATFORMS, false)) {
|
||||
throw new Error(
|
||||
'There can be only one platform. Destroy the previous one to create a new one.');
|
||||
}
|
||||
@ -103,7 +106,8 @@ export function createPlatformFactory(
|
||||
providers: Provider[] = []): (extraProviders?: Provider[]) => PlatformRef {
|
||||
const marker = new InjectionToken(`Platform: ${name}`);
|
||||
return (extraProviders: Provider[] = []) => {
|
||||
if (!getPlatform()) {
|
||||
let platform = getPlatform();
|
||||
if (!platform || platform.injector.get(ALLOW_MULTIPLE_PLATFORMS, false)) {
|
||||
if (parentPlatformFactory) {
|
||||
parentPlatformFactory(
|
||||
providers.concat(extraProviders).concat({provide: marker, useValue: true}));
|
||||
@ -117,8 +121,7 @@ export function createPlatformFactory(
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that there currently is a platform
|
||||
* which contains the given token as a provider.
|
||||
* Checks that there currently is a platform which contains the given token as a provider.
|
||||
*
|
||||
* @experimental APIs related to application bootstrap are currently under review.
|
||||
*/
|
||||
|
@ -14,6 +14,7 @@ import {AnimationSequencePlayer as AnimationSequencePlayer_} from './animation/a
|
||||
import * as animationUtils from './animation/animation_style_util';
|
||||
import {AnimationStyles as AnimationStyles_} from './animation/animation_styles';
|
||||
import {AnimationTransition} from './animation/animation_transition';
|
||||
import {ALLOW_MULTIPLE_PLATFORMS} from './application_ref';
|
||||
import * as application_tokens from './application_tokens';
|
||||
import * as change_detection_util from './change_detection/change_detection_util';
|
||||
import * as constants from './change_detection/constants';
|
||||
@ -124,7 +125,8 @@ export const __core_private__: {
|
||||
FILL_STYLE_FLAG: typeof FILL_STYLE_FLAG_,
|
||||
isPromise: typeof isPromise,
|
||||
isObservable: typeof isObservable,
|
||||
AnimationTransition: typeof AnimationTransition
|
||||
AnimationTransition: typeof AnimationTransition,
|
||||
ALLOW_MULTIPLE_PLATFORMS: typeof ALLOW_MULTIPLE_PLATFORMS,
|
||||
view_utils: typeof view_utils,
|
||||
ERROR_COMPONENT_TYPE: typeof ERROR_COMPONENT_TYPE,
|
||||
viewEngine: typeof viewEngine,
|
||||
@ -180,6 +182,7 @@ export const __core_private__: {
|
||||
isPromise: isPromise,
|
||||
isObservable: isObservable,
|
||||
AnimationTransition: AnimationTransition,
|
||||
ALLOW_MULTIPLE_PLATFORMS: ALLOW_MULTIPLE_PLATFORMS,
|
||||
ERROR_COMPONENT_TYPE: ERROR_COMPONENT_TYPE,
|
||||
TransitionEngine: TransitionEngine
|
||||
} as any /* TODO(misko): export these using omega names instead */;
|
||||
|
Reference in New Issue
Block a user