feat(bootstrap): remove the need for explicit reflection setup in bootstrap code

BREAKING CHANGES:

Dart applications and TypeScript applications meant to transpile to Dart must now
import `package:angular2/bootstrap.dart` instead of `package:angular2/angular2.dart`
in their bootstrap code. `package:angular2/angular2.dart` no longer export the
bootstrap function. The transformer rewrites imports of `bootstrap.dart` and calls
to `bootstrap` to `bootstrap_static.dart` and `bootstrapStatic` respectively.
This commit is contained in:
yjbanov
2015-07-22 10:18:04 -07:00
parent 55e8dca8de
commit 3531bb7118
119 changed files with 896 additions and 827 deletions

View File

@ -1,6 +1,4 @@
import {bootstrap, Component, View} from 'angular2/angular2';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
import {bootstrap, Component, View} from 'angular2/bootstrap';
@Component({selector: 'gestures-app'})
@View({templateUrl: 'template.html'})
@ -17,6 +15,5 @@ class GesturesCmp {
}
export function main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(GesturesCmp);
}

View File

@ -1,18 +1,7 @@
import {HelloCmp} from './index_common';
import {bootstrap} from 'angular2/angular2';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
import {bootstrap} from 'angular2/bootstrap';
export function main() {
// For Dart users: Initializing the reflector is only required for the Dart version of the
// application. When using Dart, the reflection information is not embedded by default in the
// source code to keep the size of the generated file small. Importing ReflectionCapabilities and
// initializing the reflector is required to use the reflection information from Dart mirrors.
// Dart mirrors are not intended to be use in production code.
// Angular 2 provides a transformer which generates static code rather than rely on reflection.
// For an example, run `pub serve` on the Dart application and inspect this file in your browser.
reflector.reflectionCapabilities = new ReflectionCapabilities();
// Bootstrapping only requires specifying a root component.
// The boundary between the Angular application and the rest of the page is
// the shadowDom of this root component.

View File

@ -1,11 +1,8 @@
import {HelloCmp} from './index_common';
import {bootstrap} from 'angular2/angular2';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
import {bootstrap} from 'angular2/bootstrap';
// This entry point is not transformed and exists for testing dynamic runtime
// mode.
export function main() {
// This entry point is not transformed and exists for testing purposes.
// See index.js for an explanation.
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(HelloCmp);
}

View File

@ -1,12 +1,9 @@
/// <reference path="../../../angular2/typings/rx/rx.all.d.ts" />
import {bootstrap} from 'angular2/angular2';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
import {bootstrap} from 'angular2/bootstrap';
import {httpInjectables} from 'angular2/http';
import {HttpCmp} from './http_comp';
export function main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(HttpCmp, [httpInjectables]);
}

View File

@ -1,13 +1,8 @@
import {HttpCmp} from './http_comp';
import {bootstrap} from 'angular2/angular2';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
import {bootstrap} from 'angular2/bootstrap';
import {httpInjectables} from 'angular2/http';
export function main() {
// This entry point is not transformed and exists for testing purposes.
// See index.js for an explanation.
reflector.reflectionCapabilities = new ReflectionCapabilities();
// This entry point is not transformed and exists for testing dynamic mode.
bootstrap(HttpCmp, [httpInjectables]);
}

View File

@ -1,12 +1,9 @@
/// <reference path="../../../angular2/typings/rx/rx.all.d.ts" />
import {bootstrap} from 'angular2/angular2';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
import {bootstrap} from 'angular2/bootstrap';
import {jsonpInjectables} from 'angular2/http';
import {JsonpCmp} from './jsonp_comp';
export function main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(JsonpCmp, [jsonpInjectables]);
}

View File

@ -1,13 +1,7 @@
import {JsonpCmp} from './jsonp_comp';
import {bootstrap} from 'angular2/angular2';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
import {bootstrap} from 'angular2/bootstrap';
import {jsonpInjectables} from 'angular2/http';
export function main() {
// This entry point is not transformed and exists for testing purposes.
// See index.js for an explanation.
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(JsonpCmp, [jsonpInjectables]);
}

View File

@ -1,9 +1,6 @@
import {bootstrap, Component, View} from 'angular2/angular2';
import {bootstrap, Component, View} from 'angular2/bootstrap';
import {KeyEventsPlugin} from 'angular2/src/render/dom/events/key_events';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
@Component({selector: 'key-events-app'})
@View({
template: `Click in the following area and press a key to display its name:<br>
@ -34,6 +31,5 @@ class KeyEventsApp {
}
export function main() {
reflector.reflectionCapabilities = new ReflectionCapabilities(); // for the Dart version
bootstrap(KeyEventsApp);
}

View File

@ -1,4 +1,4 @@
import {bootstrap, Component, View, NgFor} from 'angular2/angular2';
import {bootstrap, Component, View, NgFor} from 'angular2/bootstrap';
import {MdButton, MdAnchor} from 'angular2_material/src/components/button/button';
import {UrlResolver} from 'angular2/src/services/url_resolver';
import {commonDemoSetup, DemoUrlResolver} from '../demo_common';

View File

@ -1,4 +1,4 @@
import {bootstrap, Component, Directive, View} from 'angular2/angular2';
import {bootstrap, Component, Directive, View} from 'angular2/bootstrap';
import {MdCheckbox} from 'angular2_material/src/components/checkbox/checkbox';
import {UrlResolver} from 'angular2/src/services/url_resolver';
import {commonDemoSetup, DemoUrlResolver} from '../demo_common';

View File

@ -9,14 +9,11 @@ import {
} from 'angular2/src/facade/lang';
import {DOM} from 'angular2/src/dom/dom_adapter';
import {Injectable} from 'angular2/di';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
import {reflector} from 'angular2/src/reflection/reflection';
import {BrowserDomAdapter} from 'angular2/src/dom/browser_adapter';
export function commonDemoSetup(): void {
BrowserDomAdapter.makeCurrent();
reflector.reflectionCapabilities = new ReflectionCapabilities();
}
@Injectable()

View File

@ -1,4 +1,4 @@
import {bootstrap, ElementRef, ComponentRef, Component, View} from 'angular2/angular2';
import {bootstrap, ElementRef, ComponentRef, Component, View} from 'angular2/bootstrap';
import {
MdDialog,
MdDialogRef,

View File

@ -1,4 +1,4 @@
import {bootstrap, Component, View} from 'angular2/angular2';
import {bootstrap, Component, View} from 'angular2/bootstrap';
import {MdGridList, MdGridTile} from 'angular2_material/src/components/grid_list/grid_list';
import {UrlResolver} from 'angular2/src/services/url_resolver';
import {commonDemoSetup, DemoUrlResolver} from '../demo_common';

View File

@ -1,4 +1,4 @@
import {bootstrap, Component, View} from 'angular2/angular2';
import {bootstrap, Component, View} from 'angular2/bootstrap';
import {MdInputContainer, MdInput} from 'angular2_material/src/components/input/input';
import {UrlResolver} from 'angular2/src/services/url_resolver';
import {commonDemoSetup, DemoUrlResolver} from '../demo_common';

View File

@ -1,4 +1,4 @@
import {bootstrap, Component, View} from 'angular2/angular2';
import {bootstrap, Component, View} from 'angular2/bootstrap';
import {MdProgressLinear} from 'angular2_material/src/components/progress-linear/progress_linear';
import {UrlResolver} from 'angular2/src/services/url_resolver';
import {commonDemoSetup, DemoUrlResolver} from '../demo_common';

View File

@ -1,4 +1,4 @@
import {bootstrap, Component, View} from 'angular2/angular2';
import {bootstrap, Component, View} from 'angular2/bootstrap';
import {MdRadioButton, MdRadioGroup} from 'angular2_material/src/components/radio/radio_button';
import {MdRadioDispatcher} from 'angular2_material/src/components/radio/radio_dispatcher';
import {UrlResolver} from 'angular2/src/services/url_resolver';

View File

@ -1,4 +1,4 @@
import {bootstrap, Component, View} from 'angular2/angular2';
import {bootstrap, Component, View} from 'angular2/bootstrap';
import {MdSwitch} from 'angular2_material/src/components/switcher/switch';
import {UrlResolver} from 'angular2/src/services/url_resolver';
import {commonDemoSetup, DemoUrlResolver} from '../demo_common';

View File

@ -7,14 +7,11 @@ import {
Directive,
View,
Ancestor
} from 'angular2/angular2';
} from 'angular2/bootstrap';
import {formDirectives, NgControl, Validators, NgFormModel, FormBuilder} from 'angular2/forms';
import {RegExpWrapper, print, isPresent} from 'angular2/src/facade/lang';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
/**
* Custom validator.
*/
@ -155,6 +152,5 @@ class ModelDrivenForms {
}
export function main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(ModelDrivenForms);
}

View File

@ -11,15 +11,12 @@ import {
forwardRef,
Binding,
EventEmitter
} from 'angular2/angular2';
} from 'angular2/bootstrap';
import {formDirectives} from 'angular2/forms';
import {ListWrapper} from 'angular2/src/facade/collection';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
/**
* You can find the Angular 1 implementation of this example here:
* https://github.com/wardbell/ng1DataBinding
@ -86,29 +83,29 @@ class DataService {
@Component({selector: 'order-list-cmp'})
@View({
template: `
<h1>Orders</h1>
<h1>Orders</h1>
<div *ng-for="#order of orders" [class.warning]="order.total > order.limit">
<div>
<label>Customer name:</label>
<label>Customer name:</label>
{{order.customerName}}
</div>
<div>
<label>Limit: <input [(ng-model)]="order.limit" type="number" placeholder="Limit"></label>
<label>Limit: <input [(ng-model)]="order.limit" type="number" placeholder="Limit"></label>
</div>
<div>
<label>Number of items:</label>
<label>Number of items:</label>
{{order.items.length}}
</div>
<div>
<label>Order total:</label>
<label>Order total:</label>
{{order.total}}
</div>
<button (click)="select(order)">Select</button>
</div>
</div>
`,
directives: [formDirectives, NgFor]
})
@ -123,24 +120,24 @@ class OrderListComponent {
@Component({selector: 'order-item-cmp', properties: ['item'], events: ['delete']})
@View({
template: `
<div>
<div>
<div>
<label>Product name: <input [(ng-model)]="item.productName" type="text" placeholder="Product name"></label>
<label>Product name: <input [(ng-model)]="item.productName" type="text" placeholder="Product name"></label>
</div>
<div>
<label>Quantity: <input [(ng-model)]="item.qty" type="number" placeholder="Quantity"></label>
<label>Quantity: <input [(ng-model)]="item.qty" type="number" placeholder="Quantity"></label>
</div>
<div>
<label>Unit Price: <input [(ng-model)]="item.unitPrice" type="number" placeholder="Unit price"></label>
<label>Unit Price: <input [(ng-model)]="item.unitPrice" type="number" placeholder="Unit price"></label>
</div>
<div>
<label>Total:</label>
<label>Total:</label>
{{item.total}}
</div>
<button (click)="onDelete()">Delete</button>
</div>
`,
@ -157,25 +154,25 @@ class OrderItemComponent {
@View({
template: `
<div *ng-if="order !== null">
<h1>Selected Order</h1>
<h1>Selected Order</h1>
<div>
<label>Customer name: <input [(ng-model)]="order.customerName" type="text" placeholder="Customer name"></label>
<label>Customer name: <input [(ng-model)]="order.customerName" type="text" placeholder="Customer name"></label>
</div>
<div>
<label>Limit: <input [(ng-model)]="order.limit" type="number" placeholder="Limit"></label>
<label>Limit: <input [(ng-model)]="order.limit" type="number" placeholder="Limit"></label>
</div>
<div>
<label>Number of items:</label>
<label>Number of items:</label>
{{order.items.length}}
</div>
<div>
<label>Order total:</label>
<label>Order total:</label>
{{order.total}}
</div>
<h2>Items</h2>
<button (click)="addItem()">Add Item</button>
<order-item-cmp *ng-for="#item of order.items" [item]="item" (delete)="deleteItem(item)"></order-item-cmp>
@ -205,6 +202,5 @@ class OrderManagementApplication {
}
export function main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(OrderManagementApplication);
}

View File

@ -10,15 +10,12 @@ import {
NgValidator,
forwardRef,
Binding
} from 'angular2/angular2';
} from 'angular2/bootstrap';
import {formDirectives} from 'angular2/forms';
import {RegExpWrapper, print, isPresent, CONST_EXPR} from 'angular2/src/facade/lang';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
/**
* You can find the Angular 1 implementation of this example here:
@ -93,25 +90,25 @@ class DataService {
@Component({selector: 'full-name-cmp'})
@View({
template: `
<h1>Edit Full Name</h1>
<h1>Edit Full Name</h1>
<div>
<form>
<div>
<label>
First: <input [(ng-model)]="person.firstName" type="text" placeholder="First name">
</label>
</label>
</div>
<div>
<label>
Last: <input [(ng-model)]="person.lastName" type="text" placeholder="Last name">
</label>
</label>
</div>
<div>
<label>{{person.fullName}}</label>
</div>
</form>
</form>
</div>
`,
directives: [formDirectives]
@ -125,38 +122,38 @@ class FullNameComponent {
@View({
template: `
<h2>{{person.fullName}}</h2>
<div>
<form>
<div>
<label>First: <input [(ng-model)]="person.firstName" type="text" placeholder="First name"></label>
</div>
<div>
<label>Last: <input [(ng-model)]="person.lastName" type="text" placeholder="Last name"></label>
<div>
<label>First: <input [(ng-model)]="person.firstName" type="text" placeholder="First name"></label>
</div>
<div>
<label>Year of birth: <input [(ng-model)]="person.yearOfBirth" type="number" placeholder="Year of birth"></label>
<div>
<label>Last: <input [(ng-model)]="person.lastName" type="text" placeholder="Last name"></label>
</div>
<div>
<label>Year of birth: <input [(ng-model)]="person.yearOfBirth" type="number" placeholder="Year of birth"></label>
Age: {{person.age}}
</div>\
<div *ng-if="person.mom != null">
<label>Mom:</label>
<div *ng-if="person.mom != null">
<label>Mom:</label>
<input [(ng-model)]="person.mom.firstName" type="text" placeholder="Mom's first name">
<input [(ng-model)]="person.mom.lastName" type="text" placeholder="Mom's last name">
{{person.mom.fullName}}
{{person.mom.fullName}}
</div>
<div *ng-if="person.dad != null">
<label>Dad:</label>
<div *ng-if="person.dad != null">
<label>Dad:</label>
<input [(ng-model)]="person.dad.firstName" type="text" placeholder="Dad's first name">
<input [(ng-model)]="person.dad.lastName" type="text" placeholder="Dad's last name">
{{person.dad.fullName}}
{{person.dad.fullName}}
</div>
<div *ng-if="person.friends.length > 0">
<label>Friends:</label>
<div *ng-if="person.friends.length > 0">
<label>Friends:</label>
{{person.friendNames}}
</div>
</form>
@ -172,14 +169,14 @@ class PersonsDetailComponent {
@Component({selector: 'persons-cmp'})
@View({
template: `
<h1>FullName Demo</h1>
<h1>FullName Demo</h1>
<div>
<ul>
<li *ng-for="#person of persons">
<li *ng-for="#person of persons">
<label (click)="select(person)">{{person.fullName}}</label>
</li>
</li>
</ul>
<person-detail-cmp></person-detail-cmp>
</div>
`,
@ -199,7 +196,7 @@ class PersonsComponent {
template: `
<button (click)="switchToEditName()">Edit Full Name</button>
<button (click)="switchToPersonList()">Person List</button>
<full-name-cmp *ng-if="mode == 'editName'"></full-name-cmp>
<persons-cmp *ng-if="mode == 'personList'"></persons-cmp>
`,
@ -213,6 +210,5 @@ class PersonManagementApplication {
}
export function main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(PersonManagementApplication);
}

View File

@ -1,7 +1,5 @@
import {BaseException} from 'angular2/src/facade/lang';
import {bootstrap, Component, View} from 'angular2/angular2';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
import {bootstrap, Component, View} from 'angular2/bootstrap';
@Component({
selector: 'error-app',
@ -15,6 +13,5 @@ export class ErrorComponent {
}
export function main() {
reflector.reflectionCapabilities = new ReflectionCapabilities(); // for the Dart version
bootstrap(ErrorComponent);
}

View File

@ -10,14 +10,11 @@ import {
NgValidator,
forwardRef,
Binding
} from 'angular2/angular2';
} from 'angular2/bootstrap';
import {formDirectives, NgControl, Validators, NgForm} from 'angular2/forms';
import {RegExpWrapper, print, isPresent, CONST_EXPR} from 'angular2/src/facade/lang';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
/**
* A domain model we are binding the form controls to.
*/
@ -168,6 +165,5 @@ class TemplateDrivenForms {
}
export function main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(TemplateDrivenForms);
}

View File

@ -1,7 +1,5 @@
import {bootstrap, NgFor, Component, View} from 'angular2/angular2';
import {bootstrap, NgFor, Component, View} from 'angular2/bootstrap';
import {Store, Todo, TodoFactory} from './services/TodoStore';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
@Component({selector: 'todo-app', viewInjector: [Store, TodoFactory]})
@View({templateUrl: 'todo.html', directives: [NgFor]})
@ -44,6 +42,5 @@ class TodoApp {
}
export function main() {
reflector.reflectionCapabilities = new ReflectionCapabilities(); // for the Dart version
bootstrap(TodoApp);
}

View File

@ -1,6 +1,4 @@
import {bootstrap, Component, View, NgFor} from 'angular2/angular2';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
import {bootstrap, Component, View, NgFor} from 'angular2/bootstrap';
import {Zippy} from './zippy';
@Component({selector: 'zippy-app'})
@ -22,6 +20,5 @@ class ZippyApp {
}
export function main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(ZippyApp);
}