docs(Http): add docs for Http lib

Fixes #2442
This commit is contained in:
Jeff Cross
2015-06-09 15:18:57 -07:00
parent e68e69e7e5
commit 5b5ffe75d0
18 changed files with 558 additions and 218 deletions

View File

@ -1,20 +0,0 @@
import {Directive, ViewContainerRef, ProtoViewRef} from "angular2/angular2";
@Directive({selector: '[assign-local]', properties: ['localVariable: assignLocalTo']})
export class LocalVariable {
viewContainer: ViewContainerRef;
protoViewRef: ProtoViewRef;
view: any;
constructor(viewContainer: ViewContainerRef, protoViewRef: ProtoViewRef) {
this.viewContainer = viewContainer;
this.protoViewRef = protoViewRef;
}
set localVariable(exp) {
if (!this.viewContainer.length) {
this.view = this.viewContainer.create(this.protoViewRef);
}
this.view.setLocal("$implicit", exp);
}
}

View File

@ -1,30 +1,21 @@
import {bootstrap, Component, View, NgFor, NgIf, Inject} from 'angular2/angular2';
import {httpInjectables} from 'angular2/http';
import {HttpFactory} from 'angular2/src/http/http';
import {IHttp} from 'angular2/src/http/interfaces';
import {Response} from 'angular2/src/http/static_response';
import {LocalVariable} from './assign_local_directive';
import {bootstrap, Component, View, NgFor, Inject} from 'angular2/angular2';
import {Http, httpInjectables} from 'angular2/http';
@Component({selector: 'http-app', appInjector: [httpInjectables]})
@Component({selector: 'http-app'})
@View({
directives: [NgFor, NgIf, LocalVariable],
directives: [NgFor],
template: `
<h1>people</h1>
<div *assign-local="#unwrappedPeople to people | rx">
<ul *ng-if="unwrappedPeople" class="people">
<li *ng-for="#person of unwrappedPeople">
hello, {{person.name}}
</li>
</ul>
<span *ng-if="!unwrappedPeople">
Fetching people...
</span>
</div>
<ul class="people">
<li *ng-for="#person of people">
hello, {{person.name}}
</li>
</ul>
`
})
export class HttpCmp {
people: Rx.Observable<Object>;
constructor(@Inject(HttpFactory) http: IHttp) {
this.people = http('./people.json').map(res => res.json());
people: Object;
constructor(http: Http) {
http.get('./people.json').map(res => res.json()).subscribe(people => this.people = people);
}
}

View File

@ -2,29 +2,13 @@
import {
bootstrap,
ElementRef,
Component,
Directive,
View,
Injectable,
NgFor,
NgIf,
Inject
} from 'angular2/angular2';
import {bind} from 'angular2/di';
import {PipeRegistry, defaultPipes} from 'angular2/change_detection';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
import {httpBindings} from 'angular2/http';
import {Http} from 'angular2/src/http/http';
import {IHttp} from 'angular2/src/http/interfaces';
import {Response} from 'angular2/src/http/static_response';
import {LocalVariable} from './assign_local_directive';
import {RxPipeFactory} from './rx_pipe';
import {httpInjectables} from 'angular2/http';
import {HttpCmp} from './http_comp';
export function main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
defaultPipes.rx = [new RxPipeFactory()] bootstrap(
HttpCmp, [bind(PipeRegistry).toValue(new PipeRegistry(defaultPipes))]);
bootstrap(HttpCmp, [httpInjectables]);
}

View File

@ -1,15 +1,13 @@
import {HttpCmp} from './http_comp';
import {bootstrap} from 'angular2/angular2';
import {bind} from 'angular2/di';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
import {PipeRegistry, defaultPipes} from 'angular2/change_detection';
import {RxPipeFactory} from './rx_pipe';
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();
defaultPipes.rx = [new RxPipeFactory()] bootstrap(
HttpCmp, [bind(PipeRegistry).toValue(new PipeRegistry(defaultPipes))]);
bootstrap(HttpCmp, [httpInjectables]);
}

View File

@ -1,38 +0,0 @@
/// <reference path="../../../angular2/typings/rx/rx.all.d.ts" />
import {isBlank, isPresent, CONST} from 'angular2/src/facade/lang';
import {Observable, ObservableWrapper} from 'angular2/src/facade/async';
import {Pipe, WrappedValue, PipeFactory} from 'angular2/src/change_detection/pipes/pipe';
import {ObservablePipe} from 'angular2/src/change_detection/pipes/observable_pipe';
import {ChangeDetectorRef} from 'angular2/src/change_detection/change_detector_ref';
import * as Rx from 'rx';
export class RxPipe extends ObservablePipe {
supports(obs): boolean {
if (Rx.hasOwnProperty('default')) {
return obs instanceof (<any>Rx).default.Rx.Observable;
} else {
return obs instanceof <any>Rx.Observable;
}
}
_subscribe(obs): void {
this._observable = obs;
this._subscription =
(<any>obs).subscribe(value => {this._updateLatestValue(value)}, e => { throw e; });
}
}
/**
* Provides a factory for [ObervablePipe].
*
* @exportedAs angular2/pipes
*/
@CONST()
export class RxPipeFactory extends PipeFactory {
constructor() { super(); }
supports(obs): boolean { return obs instanceof (<any>Rx).default.Rx.Observable }
create(cdRef): Pipe { return new RxPipe(cdRef); }
}