docs(http): move examples to `@usageNotes` (#26039)

PR Close #26039
This commit is contained in:
Pete Bacon Darwin 2018-09-20 15:01:01 +01:00 committed by Kara Erickson
parent fc4b993d98
commit 32ad2438ca
8 changed files with 32 additions and 54 deletions

View File

@ -209,6 +209,7 @@ export class CookieXSRFStrategy implements XSRFStrategy {
* overridden if a different backend implementation should be used, * overridden if a different backend implementation should be used,
* such as in a node backend. * such as in a node backend.
* *
* @usageNotes
* ### Example * ### Example
* *
* ``` * ```

View File

@ -26,6 +26,7 @@ import {ResponseOptionsArgs} from './interfaces';
* This class may be used in tests to build {@link Response Responses} for * This class may be used in tests to build {@link Response Responses} for
* mock responses (see {@link MockBackend}). * mock responses (see {@link MockBackend}).
* *
* @usageNotes
* ### Example * ### Example
* *
* ```typescript * ```typescript
@ -84,6 +85,7 @@ export class ResponseOptions {
* This may be useful when sharing a base `ResponseOptions` object inside tests, * This may be useful when sharing a base `ResponseOptions` object inside tests,
* where certain properties may change from test to test. * where certain properties may change from test to test.
* *
* @usageNotes
* ### Example * ### Example
* *
* ```typescript * ```typescript
@ -123,6 +125,7 @@ export class ResponseOptions {
* when configuring an {@link Injector}, in order to override the default options * when configuring an {@link Injector}, in order to override the default options
* used by {@link Http} to create {@link Response Responses}. * used by {@link Http} to create {@link Response Responses}.
* *
* @usageNotes
* ### Example * ### Example
* *
* ```typescript * ```typescript

View File

@ -13,6 +13,7 @@
* The only known difference between this `Headers` implementation and the spec is the * The only known difference between this `Headers` implementation and the spec is the
* lack of an `entries` method. * lack of an `entries` method.
* *
* @usageNotes
* ### Example * ### Example
* *
* ``` * ```

View File

@ -47,6 +47,7 @@ function mergeOptions(
* `request` returns an `Observable` which will emit a single {@link Response} when a * `request` returns an `Observable` which will emit a single {@link Response} when a
* response is received. * response is received.
* *
* @usageNotes
* ### Example * ### Example
* *
* ```typescript * ```typescript

View File

@ -21,6 +21,7 @@ import {Headers} from './headers';
* usually instantiated by end-users, it is the primary object interacted with when it comes time to * usually instantiated by end-users, it is the primary object interacted with when it comes time to
* add data to a view. * add data to a view.
* *
* @usageNotes
* ### Example * ### Example
* *
* ``` * ```

View File

@ -25,9 +25,9 @@ function paramParser(rawParams: string = ''): Map<string, string[]> {
* @deprecated see https://angular.io/guide/http * @deprecated see https://angular.io/guide/http
**/ **/
export class QueryEncoder { export class QueryEncoder {
encodeKey(k: string): string { return standardEncoding(k); } encodeKey(key: string): string { return standardEncoding(key); }
encodeValue(v: string): string { return standardEncoding(v); } encodeValue(value: string): string { return standardEncoding(value); }
} }
function standardEncoding(v: string): string { function standardEncoding(v: string): string {

View File

@ -16,6 +16,26 @@ import {take} from 'rxjs/operators';
* *
* Mock Connection to represent a {@link Connection} for tests. * Mock Connection to represent a {@link Connection} for tests.
* *
* @usageNotes
* ### Example of `mockRespond()`
*
* ```
* var connection;
* backend.connections.subscribe(c => connection = c);
* http.request('data.json').subscribe(res => console.log(res.text()));
* connection.mockRespond(new Response(new ResponseOptions({ body: 'fake response' }))); //logs
* 'fake response'
* ```
*
* ### Example of `mockError()`
*
* ```
* var connection;
* backend.connections.subscribe(c => connection = c);
* http.request('data.json').subscribe(res => res, err => console.log(err)));
* connection.mockError(new Error('error'));
* ```
*
* @deprecated see https://angular.io/guide/http * @deprecated see https://angular.io/guide/http
*/ */
export class MockConnection implements Connection { export class MockConnection implements Connection {
@ -48,16 +68,6 @@ export class MockConnection implements Connection {
* Sends a mock response to the connection. This response is the value that is emitted to the * Sends a mock response to the connection. This response is the value that is emitted to the
* {@link EventEmitter} returned by {@link Http}. * {@link EventEmitter} returned by {@link Http}.
* *
* ### Example
*
* ```
* var connection;
* backend.connections.subscribe(c => connection = c);
* http.request('data.json').subscribe(res => console.log(res.text()));
* connection.mockRespond(new Response(new ResponseOptions({ body: 'fake response' }))); //logs
* 'fake response'
* ```
*
*/ */
mockRespond(res: Response) { mockRespond(res: Response) {
if (this.readyState === ReadyState.Done || this.readyState === ReadyState.Cancelled) { if (this.readyState === ReadyState.Done || this.readyState === ReadyState.Cancelled) {
@ -87,15 +97,6 @@ export class MockConnection implements Connection {
* returned * returned
* from {@link Http}. * from {@link Http}.
* *
* ### Example
*
* ```
* var connection;
* backend.connections.subscribe(c => connection = c);
* http.request('data.json').subscribe(res => res, err => console.log(err)));
* connection.mockError(new Error('error'));
* ```
*
*/ */
mockError(err?: Error) { mockError(err?: Error) {
// Matches ResourceLoader semantics // Matches ResourceLoader semantics
@ -110,6 +111,7 @@ export class MockConnection implements Connection {
* This class can be injected in tests, and should be used to override providers * This class can be injected in tests, and should be used to override providers
* to other backends, such as {@link XHRBackend}. * to other backends, such as {@link XHRBackend}.
* *
* @usageNotes
* ### Example * ### Example
* *
* ``` * ```
@ -187,8 +189,6 @@ export class MockConnection implements Connection {
* }); * });
* ``` * ```
* *
* This method only exists in the mock implementation, not in real Backends.
*
* @deprecated see https://angular.io/guide/http * @deprecated see https://angular.io/guide/http
*/ */
@Injectable() @Injectable()
@ -198,35 +198,6 @@ export class MockBackend implements ConnectionBackend {
* of {@link MockConnection} instances that have been created by this backend. Can be subscribed * of {@link MockConnection} instances that have been created by this backend. Can be subscribed
* to in order to respond to connections. * to in order to respond to connections.
* *
* ### Example
*
* ```
* import {Injector} from '@angular/core';
* import {fakeAsync, tick} from '@angular/core/testing';
* import {BaseRequestOptions, ConnectionBackend, Http, RequestOptions} from '@angular/http';
* import {Response, ResponseOptions} from '@angular/http';
* import {MockBackend, MockConnection} from '@angular/http/testing';
*
* it('should get a response', fakeAsync(() => {
* let connection:
* MockConnection; // this will be set when a new connection is emitted from the
* // backend.
* let text: string; // this will be set from mock response
* let injector = Injector.create([
* {provide: ConnectionBackend, useClass: MockBackend},
* {provide: RequestOptions, useClass: BaseRequestOptions},
* Http,
* ]);
* let backend = injector.get(ConnectionBackend);
* let http = injector.get(Http);
* backend.connections.subscribe((c: MockConnection) => connection = c);
* http.request('something.json').toPromise().then((res: any) => text = res.text());
* connection.mockRespond(new Response(new ResponseOptions({body: 'Something'})));
* tick();
* expect(text).toBe('Something');
* }));
* ```
*
* This property only exists in the mock implementation, not in real Backends. * This property only exists in the mock implementation, not in real Backends.
*/ */
connections: any; //<MockConnection> connections: any; //<MockConnection>

View File

@ -97,8 +97,8 @@ export declare class JsonpModule {
/** @deprecated */ /** @deprecated */
export declare class QueryEncoder { export declare class QueryEncoder {
encodeKey(k: string): string; encodeKey(key: string): string;
encodeValue(v: string): string; encodeValue(value: string): string;
} }
/** @deprecated */ /** @deprecated */