feat(core): extract platforms out of core

Currently, core depends on the browser, which means that other platforms (e.g., NativeScript or webworker) cannot use the bootstrapping logic core provides.
This PR extract makes bootstrapping logic in core completely platform-independent. The browser-specific code was moved to "angular2/platforms/browser".

BREAKING CHANGE

A few private helpers (e.g., platformCommon or applicationCommon) were removed or replaced with other helpers. Look at PLATFORM_COMMON_PROVIDERS, APPLICATION_COMMON_PROVIDERS, BROWSER_PROVIDERS, BROWSER_APP_PROVIDERS to see if they export the providers you need.

Closes #5219

Closes #5280
This commit is contained in:
vsavkin
2015-11-13 11:21:16 -08:00
committed by Victor Savkin
parent d9f362a713
commit 0eab4fc72c
37 changed files with 450 additions and 469 deletions

View File

@ -40,7 +40,7 @@ import {
import {UrlResolver} from 'angular2/src/compiler/url_resolver';
import {Testability} from 'angular2/src/core/testability/testability';
import {XHR} from 'angular2/src/compiler/xhr';
import {XHRImpl} from 'angular2/src/compiler/xhr_impl';
import {XHRImpl} from 'angular2/src/platform/browser/xhr_impl';
import {Serializer} from 'angular2/src/web_workers/shared/serializer';
import {ON_WEB_WORKER} from 'angular2/src/web_workers/shared/api';
import {RenderProtoViewRefStore} from 'angular2/src/web_workers/shared/render_proto_view_ref_store';

View File

@ -26,11 +26,12 @@ import {
} from 'angular2/src/web_workers/shared/service_message_broker';
import {MessageBus} from 'angular2/src/web_workers/shared/message_bus';
import {
platformCommon,
PlatformRef,
ApplicationRef,
applicationCommonProviders
} from 'angular2/src/core/application_ref';
APPLICATION_COMMON_PROVIDERS,
PLATFORM_COMMON_PROVIDERS
} from 'angular2/core';
import * as core from 'angular2/core';
import {Serializer} from "angular2/src/web_workers/shared/serializer";
import {ON_WEB_WORKER} from "angular2/src/web_workers/shared/api";
import {RenderProtoViewRefStore} from 'angular2/src/web_workers/shared/render_proto_view_ref_store';
@ -42,7 +43,7 @@ import {SETUP_CHANNEL} from 'angular2/src/web_workers/shared/messaging_api';
import {WebWorkerEventDispatcher} from 'angular2/src/web_workers/worker/event_dispatcher';
import {ComponentRef} from 'angular2/src/core/linker/dynamic_component_loader';
import {NgZone} from 'angular2/src/core/zone/ng_zone';
import {compilerProviders} from 'angular2/src/compiler/compiler';
import {COMPILER_PROVIDERS} from 'angular2/src/compiler/compiler';
/**
* Initialize the Angular 'platform' on the page in a manner suitable for applications
@ -73,15 +74,17 @@ import {compilerProviders} from 'angular2/src/compiler/compiler';
* them if a platform did not exist already. If it did exist, however, an error will be
* thrown.
*
*##For Web Worker Appplications
*##For Web Worker Applications
*
* This version of `platform` initializes Angular for use with applications
* that do not directly touch the DOM, such as applications which run in a
* web worker context. Applications that need direct access to the DOM should
* use `platform` from `core/application_common` instead.
*/
export function platform(bindings?: Array<Type | Provider | any[]>): PlatformRef {
return platformCommon(bindings);
export function platform(providers?: Array<Type | Provider | any[]>): PlatformRef {
let platformProviders =
isPresent(providers) ? [PLATFORM_COMMON_PROVIDERS, providers] : PLATFORM_COMMON_PROVIDERS;
return core.platform(platformProviders);
}
class PrintLogger {
@ -94,7 +97,7 @@ class PrintLogger {
function webWorkerProviders(appComponentType, bus: MessageBus,
initData: {[key: string]: any}): Array<Type | Provider | any[]> {
return [
compilerProviders(),
COMPILER_PROVIDERS,
Serializer,
provide(MessageBus, {useValue: bus}),
provide(ClientMessageBrokerFactory, {useClass: ClientMessageBrokerFactory_}),
@ -129,7 +132,7 @@ export function bootstrapWebWorkerCommon(
var emitter = bus.from(SETUP_CHANNEL);
subscription = ObservableWrapper.subscribe(emitter, (message: {[key: string]: any}) => {
var bindings =
[applicationCommonProviders(), webWorkerProviders(appComponentType, bus, message)];
[APPLICATION_COMMON_PROVIDERS, webWorkerProviders(appComponentType, bus, message)];
if (isPresent(appProviders)) {
bindings.push(appProviders);
}