docs(API): 翻译完了 HttpResponse

This commit is contained in:
Zhicheng Wang 2018-09-04 16:37:03 +08:00
parent 2a1fbec879
commit d9a50a8452
2 changed files with 77 additions and 1 deletions

View File

@ -77,7 +77,7 @@
[x] | common/formatDate | 0.21 [x] | common/formatDate | 0.21
[x] | core/ComponentFactoryResolver | 0.20 [x] | core/ComponentFactoryResolver | 0.20
[x] | forms/Form | 0.20 [x] | forms/Form | 0.20
[ ] | common/http/HttpErrorResponse | 0.20 [x] | common/http/HttpErrorResponse | 0.20
[ ] | core/QueryList | 0.19 [ ] | core/QueryList | 0.19
[ ] | forms | 0.19 [ ] | forms | 0.19
[ ] | animations/state | 0.19 [ ] | animations/state | 0.19

View File

@ -11,36 +11,49 @@ import {HttpHeaders} from './headers';
/** /**
* Type enumeration for the different kinds of `HttpEvent`. * Type enumeration for the different kinds of `HttpEvent`.
* *
* `HttpEvent`
* *
*/ */
export enum HttpEventType { export enum HttpEventType {
/** /**
* The request was sent out over the wire. * The request was sent out over the wire.
*
* 线
*/ */
Sent, Sent,
/** /**
* An upload progress event was received. * An upload progress event was received.
*
*
*/ */
UploadProgress, UploadProgress,
/** /**
* The response status code and headers were received. * The response status code and headers were received.
*
*
*/ */
ResponseHeader, ResponseHeader,
/** /**
* A download progress event was received. * A download progress event was received.
*
*
*/ */
DownloadProgress, DownloadProgress,
/** /**
* The full response including the body was received. * The full response including the body was received.
*
*
*/ */
Response, Response,
/** /**
* A custom event from an interceptor or a backend. * A custom event from an interceptor or a backend.
*
*
*/ */
User, User,
} }
@ -49,21 +62,28 @@ export enum HttpEventType {
* Base interface for progress events. * Base interface for progress events.
* *
* *
*
*/ */
export interface HttpProgressEvent { export interface HttpProgressEvent {
/** /**
* Progress event type is either upload or download. * Progress event type is either upload or download.
*
*
*/ */
type: HttpEventType.DownloadProgress|HttpEventType.UploadProgress; type: HttpEventType.DownloadProgress|HttpEventType.UploadProgress;
/** /**
* Number of bytes uploaded or downloaded. * Number of bytes uploaded or downloaded.
*
*
*/ */
loaded: number; loaded: number;
/** /**
* Total number of bytes to upload or download. Depending on the request or * Total number of bytes to upload or download. Depending on the request or
* response, this may not be computable and thus may not be present. * response, this may not be computable and thus may not be present.
*
*
*/ */
total?: number; total?: number;
} }
@ -71,6 +91,7 @@ export interface HttpProgressEvent {
/** /**
* A download progress event. * A download progress event.
* *
*
* *
*/ */
export interface HttpDownloadProgressEvent extends HttpProgressEvent { export interface HttpDownloadProgressEvent extends HttpProgressEvent {
@ -79,7 +100,11 @@ export interface HttpDownloadProgressEvent extends HttpProgressEvent {
/** /**
* The partial response body as downloaded so far. * The partial response body as downloaded so far.
* *
*
*
* Only present if the responseType was `text`. * Only present if the responseType was `text`.
*
* responseType `text`
*/ */
partialText?: string; partialText?: string;
} }
@ -87,6 +112,7 @@ export interface HttpDownloadProgressEvent extends HttpProgressEvent {
/** /**
* An upload progress event. * An upload progress event.
* *
*
* *
*/ */
export interface HttpUploadProgressEvent extends HttpProgressEvent { export interface HttpUploadProgressEvent extends HttpProgressEvent {
@ -98,6 +124,8 @@ export interface HttpUploadProgressEvent extends HttpProgressEvent {
* when a request may be retried multiple times, to distinguish between * when a request may be retried multiple times, to distinguish between
* retries on the final event stream. * retries on the final event stream.
* *
*
*
* *
*/ */
export interface HttpSentEvent { type: HttpEventType.Sent; } export interface HttpSentEvent { type: HttpEventType.Sent; }
@ -105,9 +133,12 @@ export interface HttpSentEvent { type: HttpEventType.Sent; }
/** /**
* A user-defined event. * A user-defined event.
* *
*
*
* Grouping all custom events under this type ensures they will be handled * Grouping all custom events under this type ensures they will be handled
* and forwarded by all implementations of interceptors. * and forwarded by all implementations of interceptors.
* *
*
* *
*/ */
export interface HttpUserEvent<T> { type: HttpEventType.User; } export interface HttpUserEvent<T> { type: HttpEventType.User; }
@ -116,8 +147,11 @@ export interface HttpUserEvent<T> { type: HttpEventType.User; }
* An error that represents a failed attempt to JSON.parse text coming back * An error that represents a failed attempt to JSON.parse text coming back
* from the server. * from the server.
* *
* JSON.parse
*
* It bundles the Error object with the actual response body that failed to parse. * It bundles the Error object with the actual response body that failed to parse.
* *
* `Error`
* *
*/ */
export interface HttpJsonParseError { export interface HttpJsonParseError {
@ -128,8 +162,11 @@ export interface HttpJsonParseError {
/** /**
* Union type for all possible events on the response stream. * Union type for all possible events on the response stream.
* *
*
*
* Typed according to the expected type of the response. * Typed according to the expected type of the response.
* *
*
* *
*/ */
export type HttpEvent<T> = export type HttpEvent<T> =
@ -138,38 +175,53 @@ export type HttpEvent<T> =
/** /**
* Base class for both `HttpResponse` and `HttpHeaderResponse`. * Base class for both `HttpResponse` and `HttpHeaderResponse`.
* *
* `HttpResponse` `HttpHeaderResponse`
* *
*/ */
export abstract class HttpResponseBase { export abstract class HttpResponseBase {
/** /**
* All response headers. * All response headers.
*
*
*/ */
readonly headers: HttpHeaders; readonly headers: HttpHeaders;
/** /**
* Response status code. * Response status code.
*
*
*/ */
readonly status: number; readonly status: number;
/** /**
* Textual description of response status code. * Textual description of response status code.
* *
*
*
* Do not depend on this. * Do not depend on this.
*
*
*/ */
readonly statusText: string; readonly statusText: string;
/** /**
* URL of the resource retrieved, or null if not available. * URL of the resource retrieved, or null if not available.
*
* URL `null`
*/ */
readonly url: string|null; readonly url: string|null;
/** /**
* Whether the status code falls in the 2xx range. * Whether the status code falls in the 2xx range.
*
* 2xx
*/ */
readonly ok: boolean; readonly ok: boolean;
/** /**
* Type of the response, narrowed to either the full response or the header. * Type of the response, narrowed to either the full response or the header.
*
*
*/ */
// TODO(issue/24571): remove '!'. // TODO(issue/24571): remove '!'.
readonly type !: HttpEventType.Response | HttpEventType.ResponseHeader; readonly type !: HttpEventType.Response | HttpEventType.ResponseHeader;
@ -177,8 +229,12 @@ export abstract class HttpResponseBase {
/** /**
* Super-constructor for all responses. * Super-constructor for all responses.
* *
* super
*
* The single parameter accepted is an initialization hash. Any properties * The single parameter accepted is an initialization hash. Any properties
* of the response passed there will override the default values. * of the response passed there will override the default values.
*
*
*/ */
constructor( constructor(
init: { init: {
@ -204,14 +260,19 @@ export abstract class HttpResponseBase {
* A partial HTTP response which only includes the status and header data, * A partial HTTP response which only includes the status and header data,
* but no response body. * but no response body.
* *
* HTTP
*
* `HttpHeaderResponse` is a `HttpEvent` available on the response * `HttpHeaderResponse` is a `HttpEvent` available on the response
* event stream, only when progress events are requested. * event stream, only when progress events are requested.
* *
* `HttpHeaderResponse` `HttpEvent`
* *
*/ */
export class HttpHeaderResponse extends HttpResponseBase { export class HttpHeaderResponse extends HttpResponseBase {
/** /**
* Create a new `HttpHeaderResponse` with the given parameters. * Create a new `HttpHeaderResponse` with the given parameters.
*
* `HttpHeaderResponse`
*/ */
constructor(init: { constructor(init: {
headers?: HttpHeaders, headers?: HttpHeaders,
@ -227,6 +288,8 @@ export class HttpHeaderResponse extends HttpResponseBase {
/** /**
* Copy this `HttpHeaderResponse`, overriding its contents with the * Copy this `HttpHeaderResponse`, overriding its contents with the
* given parameter hash. * given parameter hash.
*
* `HttpHeaderResponse`使
*/ */
clone(update: {headers?: HttpHeaders; status?: number; statusText?: string; url?: string;} = {}): clone(update: {headers?: HttpHeaders; status?: number; statusText?: string; url?: string;} = {}):
HttpHeaderResponse { HttpHeaderResponse {
@ -245,19 +308,26 @@ export class HttpHeaderResponse extends HttpResponseBase {
* A full HTTP response, including a typed response body (which may be `null` * A full HTTP response, including a typed response body (which may be `null`
* if one was not returned). * if one was not returned).
* *
* HTTP `null`
*
* `HttpResponse` is a `HttpEvent` available on the response event * `HttpResponse` is a `HttpEvent` available on the response event
* stream. * stream.
* *
* *
* `HttpResponse` `HttpEvent`
*/ */
export class HttpResponse<T> extends HttpResponseBase { export class HttpResponse<T> extends HttpResponseBase {
/** /**
* The response body, or `null` if one was not returned. * The response body, or `null` if one was not returned.
*
* `null`
*/ */
readonly body: T|null; readonly body: T|null;
/** /**
* Construct a new `HttpResponse`. * Construct a new `HttpResponse`.
*
* `HttpResponse`
*/ */
constructor(init: { constructor(init: {
body?: T | null, headers?: HttpHeaders; status?: number; statusText?: string; url?: string; body?: T | null, headers?: HttpHeaders; status?: number; statusText?: string; url?: string;
@ -292,6 +362,8 @@ export class HttpResponse<T> extends HttpResponseBase {
* non-successful HTTP status, an error while executing the request, * non-successful HTTP status, an error while executing the request,
* or some other failure which occurred during the parsing of the response. * or some other failure which occurred during the parsing of the response.
* *
* HTTP
*
* Any error returned on the `Observable` response stream will be * Any error returned on the `Observable` response stream will be
* wrapped in an `HttpErrorResponse` to provide additional context about * wrapped in an `HttpErrorResponse` to provide additional context about
* the state of the HTTP layer when the error occurred. The error property * the state of the HTTP layer when the error occurred. The error property
@ -299,6 +371,8 @@ export class HttpResponse<T> extends HttpResponseBase {
* from the server. * from the server.
* *
* *
* `Observable` `HttpErrorResponse` 便 HTTP
*
*/ */
export class HttpErrorResponse extends HttpResponseBase implements Error { export class HttpErrorResponse extends HttpResponseBase implements Error {
readonly name = 'HttpErrorResponse'; readonly name = 'HttpErrorResponse';
@ -307,6 +381,8 @@ export class HttpErrorResponse extends HttpResponseBase implements Error {
/** /**
* Errors are never okay, even when the status code is in the 2xx success range. * Errors are never okay, even when the status code is in the 2xx success range.
*
* `ok` `false` HTTP 2xx
*/ */
readonly ok = false; readonly ok = false;