feat(core): Add a long-form syntax for Angular bootstrapping.

This change adds a syntax for bootstrapping Angular on a page that allows more fine-grained control of the hierarchy created. platform() creates a platform injector (of which there can only be one). From the platform, .application() creates an Angular application including a Zone and all specified application bindings (e.g. for the DOM, HTTP, Compiler, Renderer, etc). At the application level, .bootstrap() will bootstrap the given component into that application.

Closes #3852
This commit is contained in:
Alex Rickabaugh
2015-09-02 15:19:26 -07:00
parent 193792c27f
commit 97d1844bfc
16 changed files with 503 additions and 408 deletions

View File

@ -1,4 +1,4 @@
library testability.get_testability;
library testability.browser_testability;
import './testability.dart';
@ -80,8 +80,14 @@ class PublicTestability implements _JsObjectProxyable {
}
}
class GetTestability {
static addToWindow(TestabilityRegistry registry) {
class BrowserGetTestability implements GetTestability {
const BrowserGetTestability();
static init() {
setTestabilityGetter(const BrowserGetTestability());
}
void addToWindow(TestabilityRegistry registry) {
var jsRegistry = js.context['ngTestabilityRegistries'];
if (jsRegistry == null) {
js.context['ngTestabilityRegistries'] = jsRegistry = new js.JsArray();
@ -106,10 +112,10 @@ class GetTestability {
return _jsify(result);
});
}
jsRegistry.add(_createRegistry(registry));
jsRegistry.add(this._createRegistry(registry));
}
static js.JsObject _createRegistry(TestabilityRegistry registry) {
js.JsObject _createRegistry(TestabilityRegistry registry) {
var object = new js.JsObject(js.context['Object']);
object['getAngularTestability'] = _jsify((Element elem,
bool findInAncestors) {

View File

@ -1,4 +1,9 @@
import {TestabilityRegistry, Testability} from 'angular2/src/core/testability/testability';
import {
TestabilityRegistry,
Testability,
GetTestability,
setTestabilityGetter
} from 'angular2/src/core/testability/testability';
import {global} from 'angular2/src/core/facade/lang';
class PublicTestability {
@ -13,8 +18,10 @@ class PublicTestability {
}
}
export class GetTestability {
static addToWindow(registry: TestabilityRegistry) {
export class BrowserGetTestability implements GetTestability {
static init() { setTestabilityGetter(new BrowserGetTestability()); }
addToWindow(registry: TestabilityRegistry): void {
global.getAngularTestability = function(elem: Element, findInAncestors: boolean = true):
PublicTestability {
var testability = registry.findTestabilityInTree(elem, findInAncestors);

View File

@ -1,8 +1,8 @@
import {Injectable} from 'angular2/src/core/di';
import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {Map, MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
import {CONST, CONST_EXPR} from 'angular2/src/core/facade/lang';
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
import * as getTestabilityModule from './get_testability';
import {NgZone} from '../zone/ng_zone';
import {PromiseWrapper} from 'angular2/src/core/facade/async';
@ -76,7 +76,7 @@ export class Testability {
export class TestabilityRegistry {
_applications: Map<any, Testability> = new Map();
constructor() { getTestabilityModule.GetTestability.addToWindow(this); }
constructor() { testabilityGetter.addToWindow(this); }
registerApplication(token: any, testability: Testability) {
this._applications.set(token, testability);
@ -99,3 +99,16 @@ export class TestabilityRegistry {
return this.findTestabilityInTree(DOM.parentElement(elem));
}
}
export interface GetTestability { addToWindow(registry: TestabilityRegistry): void; }
@CONST()
class NoopGetTestability implements GetTestability {
addToWindow(registry: TestabilityRegistry): void {}
}
export function setTestabilityGetter(getter: GetTestability): void {
testabilityGetter = getter;
}
var testabilityGetter: GetTestability = CONST_EXPR(new NoopGetTestability());