fix: cleanup public api of platform-server

BREAKING CHANGE: Parse5Adapter is no longer exported as public API, use serverBootstrap()

Parse5Adapter is an implementation detail not a public API
This commit is contained in:
Misko Hevery
2016-06-14 12:34:31 -07:00
parent 387a90e546
commit ac84468f1c
7 changed files with 89 additions and 131 deletions

View File

@ -0,0 +1,46 @@
import {PlatformLocation} from '@angular/common';
import {ComponentRef, OpaqueToken, PLATFORM_COMMON_PROVIDERS, PLATFORM_INITIALIZER, PlatformRef, ReflectiveInjector, Type, assertPlatform, coreLoadAndBootstrap, createPlatform, getPlatform} from '@angular/core';
import {BROWSER_APP_COMPILER_PROVIDERS, BROWSER_APP_PROVIDERS, BrowserPlatformLocation} from '@angular/platform-browser';
import {ReflectionCapabilities, reflector, wtfInit} from '../core_private';
import {Parse5DomAdapter} from './parse5_adapter';
const SERVER_PLATFORM_MARKER = new OpaqueToken('ServerPlatformMarker');
/**
* A set of providers to initialize the Angular platform in a server.
*
* Used automatically by `serverBootstrap`, or can be passed to {@link platform}.
*/
export const SERVER_PLATFORM_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
{provide: SERVER_PLATFORM_MARKER, useValue: true}, PLATFORM_COMMON_PROVIDERS,
{provide: PLATFORM_INITIALIZER, useValue: initParse5Adapter, multi: true},
{provide: PlatformLocation, useClass: BrowserPlatformLocation}
];
export const SERVER_APPLICATION_PROVIDERS: Array<any> =
[BROWSER_APP_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS];
function initParse5Adapter() {
Parse5DomAdapter.makeCurrent();
wtfInit();
}
export function serverPlatform(): PlatformRef {
if (!getPlatform()) {
createPlatform(ReflectiveInjector.resolveAndCreate(SERVER_PLATFORM_PROVIDERS));
}
return assertPlatform(SERVER_PLATFORM_MARKER);
}
export function serverBootstrap(
appComponentType: Type,
customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ComponentRef<any>> {
reflector.reflectionCapabilities = new ReflectionCapabilities();
let providers = [SERVER_APPLICATION_PROVIDERS, customProviders || []];
var appInjector = ReflectiveInjector.resolveAndCreate(providers, serverPlatform().injector);
return coreLoadAndBootstrap(appComponentType, appInjector);
}