chore(ts): updating to beta.16

This commit is contained in:
Filipe Silva 2016-04-21 01:12:21 +01:00 committed by Ward Bell
parent 3bc94147a7
commit 0a606a1b41
22 changed files with 59 additions and 100 deletions

View File

@ -3,9 +3,10 @@ import { bootstrap } from 'angular2/platform/browser';
import { provide } from 'angular2/core'; import { provide } from 'angular2/core';
import { XHRBackend } from 'angular2/http'; import { XHRBackend } from 'angular2/http';
import { ROUTER_PROVIDERS } from 'angular2/router';
import { LocationStrategy, import { LocationStrategy,
HashLocationStrategy, HashLocationStrategy } from 'angular2/platform/common';
ROUTER_PROVIDERS } from 'angular2/router';
import { HeroData } from './hero-data'; import { HeroData } from './hero-data';
import { InMemoryBackendService, import { InMemoryBackendService,

View File

@ -3,10 +3,12 @@ import {provide}
from 'angular2/core'; from 'angular2/core';
import {bootstrap} import {bootstrap}
from 'angular2/platform/browser'; from 'angular2/platform/browser';
import {
} from 'angular2/router';
import { import {
LocationStrategy, LocationStrategy,
HashLocationStrategy HashLocationStrategy
} from 'angular2/router'; } from 'angular2/platform/common';
// #enddocregion ng2import // #enddocregion ng2import
// #docregion appimport // #docregion appimport

View File

@ -1,25 +1,25 @@
// #docplaster // #docplaster
//#docregion //#docregion
import { Injector } from 'angular2/core'; import { ReflectiveInjector } from 'angular2/core';
import {Car, Engine, Tires} from './car'; import {Car, Engine, Tires} from './car';
import {Logger} from '../logger.service'; import {Logger} from '../logger.service';
//#docregion injector //#docregion injector
export function useInjector() { export function useInjector() {
var injector:Injector; var injector:ReflectiveInjector;
//#enddocregion injector //#enddocregion injector
/* /*
//#docregion injector-no-new //#docregion injector-no-new
// Cannot 'new' an Injector like this! // Cannot 'new' an ReflectiveInjector like this!
var injector = new Injector([Car, Engine, Tires, Logger]); var injector = new ReflectiveInjector([Car, Engine, Tires, Logger]);
//#enddocregion injector-no-new //#enddocregion injector-no-new
*/ */
//#docregion injector //#docregion injector
//#docregion injector-create-and-call //#docregion injector-create-and-call
injector = Injector.resolveAndCreate([Car, Engine, Tires, Logger]); injector = ReflectiveInjector.resolveAndCreate([Car, Engine, Tires, Logger]);
//#docregion injector-call //#docregion injector-call
var car = injector.get(Car); var car = injector.get(Car);
//#enddocregion injector-call //#enddocregion injector-call

View File

@ -30,7 +30,7 @@ export class InjectorComponent {
hero = this.heroService.getHeroes()[0]; hero = this.heroService.getHeroes()[0];
get rodent() { get rodent() {
let rous = this._injector.getOptional(ROUS); let rous = this._injector.get(ROUS, null);
if (rous) { if (rous) {
throw new Error('Aaaargh!') throw new Error('Aaaargh!')
} }

View File

@ -14,9 +14,9 @@
<script src="https://code.angularjs.org/tools/system.js"></script> <script src="https://code.angularjs.org/tools/system.js"></script>
<script src="https://code.angularjs.org/tools/typescript.js"></script> <script src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.15/angular2-polyfills.js"></script> <script src="https://code.angularjs.org/2.0.0-beta.16/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.15/Rx.js"></script> <script src="https://code.angularjs.org/2.0.0-beta.16/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.15/angular2.dev.js"></script> <script src="https://code.angularjs.org/2.0.0-beta.16/angular2.dev.js"></script>
<!-- 2. Configure SystemJS --> <!-- 2. Configure SystemJS -->
<script> <script>

View File

@ -15,9 +15,9 @@
<script src="https://code.angularjs.org/tools/system.js"></script> <script src="https://code.angularjs.org/tools/system.js"></script>
<script src="https://code.angularjs.org/tools/typescript.js"></script> <script src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.15/angular2-polyfills.js"></script> <script src="https://code.angularjs.org/2.0.0-beta.16/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.15/Rx.js"></script> <script src="https://code.angularjs.org/2.0.0-beta.16/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.15/angular2.dev.js"></script> <script src="https://code.angularjs.org/2.0.0-beta.16/angular2.dev.js"></script>
<!-- 2. Configure SystemJS --> <!-- 2. Configure SystemJS -->
<script> <script>

View File

@ -15,9 +15,9 @@
<script src="https://code.angularjs.org/tools/system.js"></script> <script src="https://code.angularjs.org/tools/system.js"></script>
<script src="https://code.angularjs.org/tools/typescript.js"></script> <script src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.15/angular2-polyfills.js"></script> <script src="https://code.angularjs.org/2.0.0-beta.16/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.15/Rx.js"></script> <script src="https://code.angularjs.org/2.0.0-beta.16/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.15/angular2.dev.js"></script> <script src="https://code.angularjs.org/2.0.0-beta.16/angular2.dev.js"></script>
<!-- 2. Configure SystemJS --> <!-- 2. Configure SystemJS -->
<script> <script>

View File

@ -19,22 +19,21 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"angular2": "2.0.0-beta.15", "angular2": "2.0.0-beta.16",
"systemjs": "0.19.26", "systemjs": "0.19.26",
"es6-shim": "^0.35.0", "es6-shim": "^0.35.0",
"reflect-metadata": "0.1.2", "reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2", "rxjs": "5.0.0-beta.2",
"zone.js": "0.6.10", "zone.js": "^0.6.12",
"a2-in-memory-web-api": "^0.1.15", "a2-in-memory-web-api": "^0.1.16",
"bootstrap": "^3.3.6" "bootstrap": "^3.3.6"
}, },
"devDependencies": { "devDependencies": {
"concurrently": "^2.0.0", "concurrently": "^2.0.0",
"lite-server": "^2.2.0", "lite-server": "^2.2.0",
"typescript": "^1.8.10", "typescript": "^1.8.10",
"typings":"^0.7.12", "typings": "^0.8.1",
"canonical-path": "0.0.2", "canonical-path": "0.0.2",
"http-server": "^0.9.0", "http-server": "^0.9.0",
@ -44,8 +43,8 @@
"karma-cli": "^0.1.2", "karma-cli": "^0.1.2",
"karma-htmlfile-reporter": "^0.2.2", "karma-htmlfile-reporter": "^0.2.2",
"karma-jasmine": "^0.3.8", "karma-jasmine": "^0.3.8",
"protractor": "^3.2.2", "protractor": "^3.3.0",
"rimraf": "^2.5.2" "rimraf": "^2.5.2"
}, },
"repository": { } "repository": {}
} }

View File

@ -10,7 +10,6 @@
<a href="#flying-heroes-impure">Flying Heroes filter pipe (impure)</a><br> <a href="#flying-heroes-impure">Flying Heroes filter pipe (impure)</a><br>
<a href="#hero-message">Async Hero Message and AsyncPipe</a><br> <a href="#hero-message">Async Hero Message and AsyncPipe</a><br>
<a href="#hero-list">Hero List with caching FetchJsonPipe</a><br> <a href="#hero-list">Hero List with caching FetchJsonPipe</a><br>
<a href="#random-pipe">Random Pipe (pure pipe / impure function)</a><br>
<hr> <hr>
@ -81,8 +80,4 @@
<a id="hero-list"></a> <a id="hero-list"></a>
<hero-list></hero-list> <hero-list></hero-list>
<hr>
<a id="random-pipe"></a>
<random-pipe></random-pipe>
<div style="margin-top:12em;"></div> <div style="margin-top:12em;"></div>

View File

@ -10,7 +10,6 @@ import {HeroBirthday2} from './hero-birthday2.component';
import {HeroListComponent} from './hero-list.component'; import {HeroListComponent} from './hero-list.component';
import {PowerBooster} from './power-booster.component'; import {PowerBooster} from './power-booster.component';
import {PowerBoostCalculator} from './power-boost-calculator.component'; import {PowerBoostCalculator} from './power-boost-calculator.component';
import {RandomPipeComponent} from './random-pipe.component';
@Component({ @Component({
selector: 'my-app', selector: 'my-app',
@ -21,8 +20,7 @@ import {RandomPipeComponent} from './random-pipe.component';
HeroBirthday, HeroBirthday,
HeroBirthday2, HeroBirthday2,
HeroListComponent, HeroListComponent,
PowerBooster, PowerBoostCalculator, PowerBooster, PowerBoostCalculator
RandomPipeComponent
], ],
providers:[HTTP_PROVIDERS] providers:[HTTP_PROVIDERS]
}) })

View File

@ -11,8 +11,8 @@ import {Pipe, PipeTransform} from 'angular2/core';
*/ */
@Pipe({name: 'exponentialStrength'}) @Pipe({name: 'exponentialStrength'})
export class ExponentialStrengthPipe implements PipeTransform { export class ExponentialStrengthPipe implements PipeTransform {
transform(value:number, [exponent]) : number { transform(value: number, exponent: string): number {
var exp = parseFloat(exponent); let exp = parseFloat(exponent);
return Math.pow(value, isNaN(exp) ? 1 : exp); return Math.pow(value, isNaN(exp) ? 1 : exp);
} }
} }

View File

@ -14,13 +14,13 @@ export class FetchJsonPipe implements PipeTransform{
constructor(private _http: Http) { } constructor(private _http: Http) { }
transform(url:string):any { transform(url: string): any {
if (url !== this.prevUrl) { if (url !== this.prevUrl) {
this.prevUrl = url; this.prevUrl = url;
this.fetched = null; this.fetched = null;
this._http.get(url) this._http.get(url)
.map( result => result.json() ) .map( result => result.json() )
.subscribe( result => this.fetched = result ) .subscribe( result => this.fetched = result );
} }
return this.fetched; return this.fetched;

View File

@ -1,24 +0,0 @@
import {Component} from 'angular2/core';
import {Pipe, PipeTransform} from 'angular2/core';
// #docregion pipe
// Pure pipe
@Pipe({ name: 'randomizer' })
export class RandomizerPipe implements PipeTransform {
// Impure function
transform() { return Math.random() * 10 ;}
}
// #enddocregion pipe
@Component({
selector: 'random-pipe',
template: `
<h2>Random Pipe (pure pipe/impure function)</h2>
<input #box (input)="0">
<p>Input value: {{box.value}}</p>
<p>Random pipe output: {{box.value | randomizer}}</p>
`,
pipes: [RandomizerPipe]
})
export class RandomPipeComponent {
}

View File

@ -7,11 +7,11 @@
}, },
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"angular2": "2.0.0-beta.15", "angular2": "2.0.0-beta.16",
"es6-shim": "^0.35.0", "es6-shim": "^0.35.0",
"reflect-metadata": "0.1.2", "reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2", "rxjs": "5.0.0-beta.2",
"zone.js": "0.6.10" "zone.js": "0.6.12"
}, },
"devDependencies": { "devDependencies": {
"concurrently": "^2.0.0", "concurrently": "^2.0.0",

View File

@ -11,17 +11,17 @@
}, },
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"angular2": "2.0.0-beta.15", "angular2": "2.0.0-beta.16",
"systemjs": "0.19.26", "systemjs": "0.19.26",
"es6-shim": "^0.35.0", "es6-shim": "^0.35.0",
"reflect-metadata": "0.1.2", "reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2", "rxjs": "5.0.0-beta.2",
"zone.js": "0.6.10" "zone.js": "0.6.12"
}, },
"devDependencies": { "devDependencies": {
"concurrently": "^2.0.0", "concurrently": "^2.0.0",
"lite-server": "^2.2.0", "lite-server": "^2.2.0",
"typescript": "^1.8.10", "typescript": "^1.8.10",
"typings":"^0.7.12" "typings":"^0.8.1"
} }
} }

View File

@ -11,7 +11,7 @@ import {AppComponent} from './app.component';
// Add these symbols to override the `LocationStrategy` // Add these symbols to override the `LocationStrategy`
import {provide} from 'angular2/core'; import {provide} from 'angular2/core';
import {LocationStrategy, import {LocationStrategy,
HashLocationStrategy} from 'angular2/router'; HashLocationStrategy} from 'angular2/platform/common';
// #enddocregion // #enddocregion
/* Can't use AppComponent ... but display as if we can /* Can't use AppComponent ... but display as if we can
// #docregion // #docregion

View File

@ -1,6 +1,6 @@
export * from 'angular2/router'; export * from 'angular2/router';
import { Directive, DynamicComponentLoader, ElementRef, import { Directive, DynamicComponentLoader, ViewContainerRef,
Injectable, Optional, Input } from 'angular2/core'; Injectable, Optional, Input } from 'angular2/core';
import { PromiseWrapper } from 'angular2/src/facade/promise'; import { PromiseWrapper } from 'angular2/src/facade/promise';
@ -52,11 +52,11 @@ export class MockRouterOutlet extends RouterOutlet {
name: string = null; name: string = null;
constructor( constructor(
_elementRef: ElementRef, _viewContainerRef: ViewContainerRef,
@Optional() _loader: DynamicComponentLoader, @Optional() _loader: DynamicComponentLoader,
_parentRouter: Router, _parentRouter: Router,
nameAttr: string) { nameAttr: string) {
super(_elementRef, _loader, _parentRouter, nameAttr); super(_viewContainerRef, _loader, _parentRouter, nameAttr);
if (nameAttr) { if (nameAttr) {
this.name = nameAttr; this.name = nameAttr;
} }

View File

@ -3,7 +3,7 @@
"icon": "home", "icon": "home",
"title": "Angular Docs", "title": "Angular Docs",
"menuTitle": "Docs Home", "menuTitle": "Docs Home",
"banner": "Welcome to <b>Angular in JavaScript</b>! The current Angular 2 release is <b>beta.15</b>. Please consult the <a href='https://github.com/angular/angular/blob/master/CHANGELOG.md' target='_blank'> Change Log</a> about recent enhancements, fixes, and breaking changes." "banner": "Welcome to <b>Angular in JavaScript</b>! The current Angular 2 release is <b>beta.16</b>. Please consult the <a href='https://github.com/angular/angular/blob/master/CHANGELOG.md' target='_blank'> Change Log</a> about recent enhancements, fixes, and breaking changes."
}, },
"quickstart": { "quickstart": {

View File

@ -3,7 +3,7 @@
"icon": "home", "icon": "home",
"title": "Angular Docs", "title": "Angular Docs",
"menuTitle": "Docs Home", "menuTitle": "Docs Home",
"banner": "Welcome to <b>Angular in TypeScript</b>! The current Angular 2 release is <b>beta.15</b>. Please consult the <a href='https://github.com/angular/angular/blob/master/CHANGELOG.md' target='_blank'> Change Log</a> about recent enhancements, fixes, and breaking changes." "banner": "Welcome to <b>Angular in TypeScript</b>! The current Angular 2 release is <b>beta.16</b>. Please consult the <a href='https://github.com/angular/angular/blob/master/CHANGELOG.md' target='_blank'> Change Log</a> about recent enhancements, fixes, and breaking changes."
}, },
"quickstart": { "quickstart": {

View File

@ -871,7 +871,8 @@ p.
They are retrieved by calling `injector.get`. They are retrieved by calling `injector.get`.
The `get` method throws an error if it can't resolve the requested service. The `get` method throws an error if it can't resolve the requested service.
We can call `getOptional` instead, which we do in one case We can call `get` with a second parameter (the value to return if the service is not found)
instead, which we do in one case
to retrieve a service (`ROUS`) that isn't registered with this or any ancestor injector. to retrieve a service (`ROUS`) that isn't registered with this or any ancestor injector.
.l-sub-section .l-sub-section

View File

@ -386,33 +386,21 @@ figure.image-display
a(id="pure-pipe-pure-fn") a(id="pure-pipe-pure-fn")
:marked :marked
### Pure pipes vs. pure functions ### Pure pipes and pure functions
When developers first hear of *pure pipes* many of them think these pipes must be *pure functions*. A pure pipe uses pure functions.
Pure functions process inputs and return values without detectable side-effects. Pure functions process inputs and return values without detectable side-effects.
Given the same input they should always return the same output. Given the same input they should always return the same output.
Pure pipes _are_ typically implemented with pure function.
The pipes we saw earlier in this chapter were implemented with pure functions. The pipes we saw earlier in this chapter were implemented with pure functions.
The built-in `DatePipe` is a pure pipe with a pure function implementation. The built-in `DatePipe` is a pure pipe with a pure function implementation.
So is our `ExponentialStrengthPipe`. So is our `ExponentialStrengthPipe`.
So is our `FlyingHeroesPipe`. So is our `FlyingHeroesPipe`.
But there is no necessary connection between a pure pipe and a pure function.
A few steps back we reviewed the `FlyingHeroesImpurePipe` &mdash; *an impure pipe with a pure function*. A few steps back we reviewed the `FlyingHeroesImpurePipe` &mdash; *an impure pipe with a pure function*.
We can also write *a pure pipe with an impure function* such as the But a *pure pipe* must always be implemented with a *pure function*. Failure to heed this warning will bring about many a console errors regarding expressions that have changed after they were checked.
`RandomizerPipe` (also in the [live example](/resources/live-examples/pipes/ts/plnkr.html))
that ignores its input value and outputs a random number. Clearly an impure function!
Yet it's perfectly well behaved as a pure pipe.
+makeExample('pipes/ts/app/random-pipe.component.ts', 'pipe','app/random-pipe.component.ts (pipe)')(format='.')
:marked
When the input changes, it outputs a new value albeit never the same value for the same input.
Remember *purity in a pipe has nothing to do with pure functions!*
*Pipe purity* is more about the purity of the input values than of the pipe itself.
.l-main-section .l-main-section
:marked :marked
@ -471,4 +459,3 @@ code-example(format="." language="html")
If these performance and minification considerations do not apply to you, you can always create your own such pipes If these performance and minification considerations do not apply to you, you can always create your own such pipes
(along the lines of the [FlyingHeroesPipe](#impure-flying-heroes)) or find them in the community. (along the lines of the [FlyingHeroesPipe](#impure-flying-heroes)) or find them in the community.

View File

@ -41,52 +41,52 @@ var _rxData = [
{ {
pattern: 'script', pattern: 'script',
from: 'node_modules/angular2/bundles/angular2.dev.js', from: 'node_modules/angular2/bundles/angular2.dev.js',
to: 'https://code.angularjs.org/2.0.0-beta.15/angular2.dev.js' to: 'https://code.angularjs.org/2.0.0-beta.16/angular2.dev.js'
}, },
{ {
pattern: 'script', pattern: 'script',
from: 'node_modules/angular2/bundles/angular2-all.umd.dev.js', from: 'node_modules/angular2/bundles/angular2-all.umd.dev.js',
to: 'https://code.angularjs.org/2.0.0-beta.15/angular2-all.umd.dev.js' to: 'https://code.angularjs.org/2.0.0-beta.16/angular2-all.umd.dev.js'
}, },
{ {
pattern: 'script', pattern: 'script',
from: 'node_modules/angular2/bundles/angular2-all.umd.js', from: 'node_modules/angular2/bundles/angular2-all.umd.js',
to: 'https://code.angularjs.org/2.0.0-beta.15/angular2-all.umd.dev.js' to: 'https://code.angularjs.org/2.0.0-beta.16/angular2-all.umd.dev.js'
}, },
{ {
pattern: 'script', pattern: 'script',
from: 'node_modules/angular2/bundles/angular2-polyfills.js', from: 'node_modules/angular2/bundles/angular2-polyfills.js',
to: 'https://code.angularjs.org/2.0.0-beta.15/angular2-polyfills.js' to: 'https://code.angularjs.org/2.0.0-beta.16/angular2-polyfills.js'
}, },
{ {
pattern: 'script', pattern: 'script',
from: 'node_modules/rxjs/bundles/Rx.js', from: 'node_modules/rxjs/bundles/Rx.js',
to: 'https://code.angularjs.org/2.0.0-beta.15/Rx.js' to: 'https://code.angularjs.org/2.0.0-beta.16/Rx.js'
}, },
{ {
pattern: 'script', pattern: 'script',
from: 'node_modules/rxjs/bundles/Rx.umd.js', from: 'node_modules/rxjs/bundles/Rx.umd.js',
to: 'https://code.angularjs.org/2.0.0-beta.15/Rx.umd.js' to: 'https://code.angularjs.org/2.0.0-beta.16/Rx.umd.js'
}, },
{ {
pattern: 'script', pattern: 'script',
from: 'node_modules/angular2/bundles/router.dev.js', from: 'node_modules/angular2/bundles/router.dev.js',
to: 'https://code.angularjs.org/2.0.0-beta.15/router.dev.js' to: 'https://code.angularjs.org/2.0.0-beta.16/router.dev.js'
}, },
{ {
pattern: 'script', pattern: 'script',
from: 'node_modules/angular2/bundles/http.dev.js', from: 'node_modules/angular2/bundles/http.dev.js',
to: 'https://code.angularjs.org/2.0.0-beta.15/http.dev.js' to: 'https://code.angularjs.org/2.0.0-beta.16/http.dev.js'
}, },
{ {
pattern: 'script', pattern: 'script',
from: 'node_modules/angular2/bundles/testing.dev.js', from: 'node_modules/angular2/bundles/testing.dev.js',
to: 'https://code.angularjs.org/2.0.0-beta.15/testing.dev.js' to: 'https://code.angularjs.org/2.0.0-beta.16/testing.dev.js'
}, },
{ {
pattern: 'script', pattern: 'script',
from: 'node_modules/angular2/es6/dev/src/testing/shims_for_IE.js', from: 'node_modules/angular2/es6/dev/src/testing/shims_for_IE.js',
to: 'https://npmcdn.com/angular2@2.0.0-beta.15/es6/dev/src/testing/shims_for_IE.js' to: 'https://npmcdn.com/angular2@2.0.0-beta.16/es6/dev/src/testing/shims_for_IE.js'
}, },
{ {
pattern: 'script', pattern: 'script',