forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 Closes angular#9237
- Loading branch information
Showing
10 changed files
with
130 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
modules/@angular/compiler-cli/integrationtest/test/projection_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// TODO: vsavkin add SERVER_PROVIDERS and SERVER_APP_PROVIDERS | ||
// TODO: vsavkin add SERVER_PROVIDERS and SERVER_APPLICATION_PROVIDERS | ||
export 'package:angular2/src/platform/server/html_adapter.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
// TODO: vsavkin add SERVER_PROVIDERS and SERVER_APP_PROVIDERS | ||
export {Parse5DomAdapter} from './src/parse5_adapter'; | ||
export {SERVER_PLATFORM_PROVIDERS, serverBootstrap, serverPlatform} from './src/server'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {PlatformLocation} from '@angular/common'; | ||
import {ComponentRef, OpaqueToken, PLATFORM_COMMON_PROVIDERS, PLATFORM_INITIALIZER, PlatformRef, ReflectiveInjector, Type, assertPlatform, coreLoadAndBootstrap, createPlatform, getPlatform} from '@angular/core'; | ||
|
||
import {ReflectionCapabilities, reflector, wtfInit} from '../core_private'; | ||
|
||
import {Parse5DomAdapter} from './parse5_adapter'; | ||
|
||
const SERVER_PLATFORM_MARKER = new OpaqueToken('ServerPlatformMarker'); | ||
|
||
function notSupported(feature: string): Error { | ||
throw new Error(`platform-server does not support '${feature}'.`); | ||
} | ||
|
||
class ServerPlatformLocation extends PlatformLocation { | ||
getBaseHrefFromDOM(): string { throw notSupported('getBaseHrefFromDOM'); }; | ||
onPopState(fn: any): void { notSupported('onPopState'); }; | ||
onHashChange(fn: any): void { notSupported('onHashChange'); }; | ||
get pathname(): string { throw notSupported('pathname'); } | ||
get search(): string { throw notSupported('search'); } | ||
get hash(): string { throw notSupported('hash'); } | ||
replaceState(state: any, title: string, url: string): void { notSupported('replaceState'); }; | ||
pushState(state: any, title: string, url: string): void { notSupported('pushState'); }; | ||
forward(): void { notSupported('forward'); }; | ||
back(): void { notSupported('back'); }; | ||
} | ||
|
||
/** | ||
* 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: ServerPlatformLocation} | ||
]; | ||
|
||
|
||
function initParse5Adapter() { | ||
Parse5DomAdapter.makeCurrent(); | ||
wtfInit(); | ||
} | ||
|
||
|
||
export function serverPlatform(): PlatformRef { | ||
if (!getPlatform()) { | ||
createPlatform(ReflectiveInjector.resolveAndCreate(SERVER_PLATFORM_PROVIDERS)); | ||
} | ||
return assertPlatform(SERVER_PLATFORM_MARKER); | ||
} | ||
|
||
/** | ||
* Used to bootstrap Angular in server environment (such as node). | ||
* | ||
* This version of bootstrap only creates platform injector and does not define anything for | ||
* application injector. It is expected that application providers are imported from other | ||
* packages such as `@angular/platform-browser` or `@angular/platform-browser-dynamic`. | ||
* | ||
* ``` | ||
* import {BROWSER_APP_PROVIDERS} from '@angular/platform-browser'; | ||
* import {BROWSER_APP_COMPILER_PROVIDERS} from '@angular/platform-browser-dynamic'; | ||
* | ||
* serverBootstrap(..., [BROWSER_APP_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS]) | ||
* ``` | ||
*/ | ||
export function serverBootstrap( | ||
appComponentType: Type, | ||
providers: Array<any /*Type | Provider | any[]*/>): Promise<ComponentRef<any>> { | ||
reflector.reflectionCapabilities = new ReflectionCapabilities(); | ||
var appInjector = ReflectiveInjector.resolveAndCreate(providers, serverPlatform().injector); | ||
return coreLoadAndBootstrap(appComponentType, appInjector); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {Component, disposePlatform} from '@angular/core'; | ||
import {afterEach, async, beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing'; | ||
import {BROWSER_APP_PROVIDERS} from '@angular/platform-browser'; | ||
import {BROWSER_APP_COMPILER_PROVIDERS} from '@angular/platform-browser-dynamic'; | ||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; | ||
import {serverBootstrap} from '@angular/platform-server'; | ||
|
||
function writeBody(html: string): any { | ||
var dom = getDOM(); | ||
var doc = dom.defaultDoc(); | ||
var body = dom.querySelector(doc, 'body'); | ||
dom.setInnerHTML(body, html); | ||
return body; | ||
} | ||
|
||
export function main() { | ||
if (getDOM().supportsDOMEvents()) return; // NODE only | ||
|
||
describe('platform-server integration', () => { | ||
|
||
afterEach(() => disposePlatform()); | ||
|
||
it('should bootstrap', async(() => { | ||
var body = writeBody('<app></app>'); | ||
serverBootstrap(MyServerApp, [ | ||
BROWSER_APP_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS | ||
]).then(() => { expect(getDOM().getText(body)).toEqual('Works!'); }); | ||
})); | ||
}); | ||
} | ||
|
||
@Component({selector: 'app', template: `Works!`}) | ||
class MyServerApp { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters