X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/angular2/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export {Http, Jsonp} from './src/http/http';

export {Headers} from './src/http/headers';

export {ResponseTypes, ReadyStates, RequestMethods} from './src/http/enums';
export {ResponseType, ReadyState, RequestMethod} from './src/http/enums';
export {URLSearchParams} from './src/http/url_search_params';

/**
Expand Down
24 changes: 12 additions & 12 deletions modules/angular2/src/http/backends/jsonp_backend.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ConnectionBackend, Connection} from '../interfaces';
import {ReadyStates, RequestMethods, ResponseTypes} from '../enums';
import {ReadyState, RequestMethod, ResponseType} from '../enums';
import {Request} from '../static_request';
import {Response} from '../static_response';
import {ResponseOptions, BaseResponseOptions} from '../base_response_options';
Expand All @@ -13,7 +13,7 @@ const JSONP_ERR_NO_CALLBACK = 'JSONP injected script did not invoke callback.';
const JSONP_ERR_WRONG_METHOD = 'JSONP requests must use GET request method.';

export abstract class JSONPConnection implements Connection {
readyState: ReadyStates;
readyState: ReadyState;
request: Request;
response: Observable<Response>;
abstract finished(data?: any): void;
Expand All @@ -28,13 +28,13 @@ export class JSONPConnection_ extends JSONPConnection {
constructor(req: Request, private _dom: BrowserJsonp,
private baseResponseOptions?: ResponseOptions) {
super();
if (req.method !== RequestMethods.Get) {
if (req.method !== RequestMethod.Get) {
throw makeTypeError(JSONP_ERR_WRONG_METHOD);
}
this.request = req;
this.response = new Observable(responseObserver => {

this.readyState = ReadyStates.Loading;
this.readyState = ReadyState.Loading;
let id = this._id = _dom.nextRequestID();

_dom.exposeConnection(id, this);
Expand All @@ -52,12 +52,12 @@ export class JSONPConnection_ extends JSONPConnection {
let script = this._script = _dom.build(url);

let onLoad = event => {
if (this.readyState === ReadyStates.Cancelled) return;
this.readyState = ReadyStates.Done;
if (this.readyState === ReadyState.Cancelled) return;
this.readyState = ReadyState.Done;
_dom.cleanup(script);
if (!this._finished) {
let responseOptions =
new ResponseOptions({body: JSONP_ERR_NO_CALLBACK, type: ResponseTypes.Error, url});
new ResponseOptions({body: JSONP_ERR_NO_CALLBACK, type: ResponseType.Error, url});
if (isPresent(baseResponseOptions)) {
responseOptions = baseResponseOptions.merge(responseOptions);
}
Expand All @@ -75,10 +75,10 @@ export class JSONPConnection_ extends JSONPConnection {
};

let onError = error => {
if (this.readyState === ReadyStates.Cancelled) return;
this.readyState = ReadyStates.Done;
if (this.readyState === ReadyState.Cancelled) return;
this.readyState = ReadyState.Done;
_dom.cleanup(script);
let responseOptions = new ResponseOptions({body: error.message, type: ResponseTypes.Error});
let responseOptions = new ResponseOptions({body: error.message, type: ResponseType.Error});
if (isPresent(baseResponseOptions)) {
responseOptions = baseResponseOptions.merge(responseOptions);
}
Expand All @@ -91,7 +91,7 @@ export class JSONPConnection_ extends JSONPConnection {
_dom.send(script);

return () => {
this.readyState = ReadyStates.Cancelled;
this.readyState = ReadyState.Cancelled;
script.removeEventListener('load', onLoad);
script.removeEventListener('error', onError);
if (isPresent(script)) {
Expand All @@ -106,7 +106,7 @@ export class JSONPConnection_ extends JSONPConnection {
// Don't leak connections
this._finished = true;
this._dom.removeConnection(this._id);
if (this.readyState === ReadyStates.Cancelled) return;
if (this.readyState === ReadyState.Cancelled) return;
this._responseData = data;
}
}
Expand Down
12 changes: 6 additions & 6 deletions modules/angular2/src/http/backends/mock_backend.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Injectable} from 'angular2/core';
import {Request} from '../static_request';
import {Response} from '../static_response';
import {ReadyStates} from '../enums';
import {ReadyState} from '../enums';
import {Connection, ConnectionBackend} from '../interfaces';
import {isPresent} from 'angular2/src/facade/lang';
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
Expand All @@ -21,7 +21,7 @@ export class MockConnection implements Connection {
* Describes the state of the connection, based on `XMLHttpRequest.readyState`, but with
* additional states. For example, state 5 indicates an aborted connection.
*/
readyState: ReadyStates;
readyState: ReadyState;

/**
* {@link Request} instance used to create the connection.
Expand All @@ -36,7 +36,7 @@ export class MockConnection implements Connection {

constructor(req: Request) {
this.response = new ReplaySubject(1).take(1);
this.readyState = ReadyStates.Open;
this.readyState = ReadyState.Open;
this.request = req;
}

Expand All @@ -55,10 +55,10 @@ export class MockConnection implements Connection {
*
*/
mockRespond(res: Response) {
if (this.readyState === ReadyStates.Done || this.readyState === ReadyStates.Cancelled) {
if (this.readyState === ReadyState.Done || this.readyState === ReadyState.Cancelled) {
throw new BaseException('Connection has already been resolved');
}
this.readyState = ReadyStates.Done;
this.readyState = ReadyState.Done;
this.response.next(res);
this.response.complete();
}
Expand All @@ -84,7 +84,7 @@ export class MockConnection implements Connection {
*/
mockError(err?: Error) {
// Matches XHR semantics
this.readyState = ReadyStates.Done;
this.readyState = ReadyState.Done;
this.response.error(err);
}
}
Expand Down
8 changes: 4 additions & 4 deletions modules/angular2/src/http/backends/xhr_backend.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ConnectionBackend, Connection} from '../interfaces';
import {ReadyStates, RequestMethods, ResponseTypes} from '../enums';
import {ReadyState, RequestMethod, ResponseType} from '../enums';
import {Request} from '../static_request';
import {Response} from '../static_response';
import {Headers} from '../headers';
Expand All @@ -24,12 +24,12 @@ export class XHRConnection implements Connection {
* `XMLHttpRequest`.
*/
response: Observable<Response>;
readyState: ReadyStates;
readyState: ReadyState;
constructor(req: Request, browserXHR: BrowserXhr, baseResponseOptions?: ResponseOptions) {
this.request = req;
this.response = new Observable(responseObserver => {
let _xhr: XMLHttpRequest = browserXHR.build();
_xhr.open(RequestMethods[req.method].toUpperCase(), req.url);
_xhr.open(RequestMethod[req.method].toUpperCase(), req.url);
// load event handler
let onLoad = () => {
// responseText is the old-school way of retrieving response (supported by IE8 & 9)
Expand Down Expand Up @@ -65,7 +65,7 @@ export class XHRConnection implements Connection {
};
// error event handler
let onError = (err) => {
var responseOptions = new ResponseOptions({body: err, type: ResponseTypes.Error});
var responseOptions = new ResponseOptions({body: err, type: ResponseType.Error});
if (isPresent(baseResponseOptions)) {
responseOptions = baseResponseOptions.merge(responseOptions);
}
Expand Down
28 changes: 14 additions & 14 deletions modules/angular2/src/http/base_request_options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {isPresent, isString} from 'angular2/src/facade/lang';
import {Headers} from './headers';
import {RequestMethods} from './enums';
import {RequestMethod} from './enums';
import {RequestOptionsArgs} from './interfaces';
import {Injectable} from 'angular2/core';
import {URLSearchParams} from './url_search_params';
Expand All @@ -19,23 +19,23 @@ import {normalizeMethodName} from './http_utils';
* ### Example ([live demo](http://plnkr.co/edit/7Wvi3lfLq41aQPKlxB4O?p=preview))
*
* ```typescript
* import {RequestOptions, Request, RequestMethods} from 'angular2/http';
* import {RequestOptions, Request, RequestMethod} from 'angular2/http';
*
* var options = new RequestOptions({
* method: RequestMethods.Post,
* method: RequestMethod.Post,
* url: 'https://google.com'
* });
* var req = new Request(options);
* console.log('req.method:', RequestMethods[req.method]); // Post
* console.log('req.method:', RequestMethod[req.method]); // Post
* console.log('options.url:', options.url); // https://google.com
* ```
*/
export class RequestOptions {
/**
* Http method with which to execute a {@link Request}.
* Acceptable methods are defined in the {@link RequestMethods} enum.
* Acceptable methods are defined in the {@link RequestMethod} enum.
*/
method: RequestMethods | string;
method: RequestMethod | string;
/**
* {@link Headers} to be attached to a {@link Request}.
*/
Expand Down Expand Up @@ -75,15 +75,15 @@ export class RequestOptions {
* ### Example ([live demo](http://plnkr.co/edit/6w8XA8YTkDRcPYpdB9dk?p=preview))
*
* ```typescript
* import {RequestOptions, Request, RequestMethods} from 'angular2/http';
* import {RequestOptions, Request, RequestMethod} from 'angular2/http';
*
* var options = new RequestOptions({
* method: RequestMethods.Post
* method: RequestMethod.Post
* });
* var req = new Request(options.merge({
* url: 'https://google.com'
* }));
* console.log('req.method:', RequestMethods[req.method]); // Post
* console.log('req.method:', RequestMethod[req.method]); // Post
* console.log('options.url:', options.url); // null
* console.log('req.url:', req.url); // https://google.com
* ```
Expand All @@ -107,7 +107,7 @@ export class RequestOptions {
* Subclass of {@link RequestOptions}, with default values.
*
* Default values:
* * method: {@link RequestMethods RequestMethods.Get}
* * method: {@link RequestMethod RequestMethod.Get}
* * headers: empty {@link Headers} object
*
* This class could be extended and bound to the {@link RequestOptions} class
Expand All @@ -134,19 +134,19 @@ export class RequestOptions {
* ### Example ([live demo](http://plnkr.co/edit/oyBoEvNtDhOSfi9YxaVb?p=preview))
*
* ```
* import {BaseRequestOptions, Request, RequestMethods} from 'angular2/http';
* import {BaseRequestOptions, Request, RequestMethod} from 'angular2/http';
*
* var options = new BaseRequestOptions();
* var req = new Request(options.merge({
* method: RequestMethods.Post,
* method: RequestMethod.Post,
* url: 'https://google.com'
* }));
* console.log('req.method:', RequestMethods[req.method]); // Post
* console.log('req.method:', RequestMethod[req.method]); // Post
* console.log('options.url:', options.url); // null
* console.log('req.url:', req.url); // https://google.com
* ```
*/
@Injectable()
export class BaseRequestOptions extends RequestOptions {
constructor() { super({method: RequestMethods.Get, headers: new Headers()}); }
constructor() { super({method: RequestMethod.Get, headers: new Headers()}); }
}
6 changes: 3 additions & 3 deletions modules/angular2/src/http/base_response_options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Injectable} from 'angular2/core';
import {isPresent, isJsObject} from 'angular2/src/facade/lang';
import {Headers} from './headers';
import {ResponseTypes} from './enums';
import {ResponseType} from './enums';
import {ResponseOptionsArgs} from './interfaces';

/**
Expand Down Expand Up @@ -52,7 +52,7 @@ export class ResponseOptions {
/**
* @internal
*/
type: ResponseTypes;
type: ResponseType;
url: string;
constructor({body, status, headers, statusText, type, url}: ResponseOptionsArgs = {}) {
this.body = isPresent(body) ? body : null;
Expand Down Expand Up @@ -147,6 +147,6 @@ export class ResponseOptions {
@Injectable()
export class BaseResponseOptions extends ResponseOptions {
constructor() {
super({status: 200, statusText: 'Ok', type: ResponseTypes.Default, headers: new Headers()});
super({status: 200, statusText: 'Ok', type: ResponseType.Default, headers: new Headers()});
}
}
6 changes: 3 additions & 3 deletions modules/angular2/src/http/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {StringMapWrapper} from 'angular2/src/facade/collection';
/**
* Supported http methods.
*/
export enum RequestMethods {
export enum RequestMethod {
Get,
Post,
Put,
Expand All @@ -18,7 +18,7 @@ export enum RequestMethods {
* [States](http://www.w3.org/TR/XMLHttpRequest/#states) from the `XMLHttpRequest` spec, but with an
* additional "CANCELLED" state.
*/
export enum ReadyStates {
export enum ReadyState {
Unsent,
Open,
HeadersReceived,
Expand All @@ -31,7 +31,7 @@ export enum ReadyStates {
* Acceptable response types to be associated with a {@link Response}, based on
* [ResponseType](https://fetch.spec.whatwg.org/#responsetype) from the Fetch spec.
*/
export enum ResponseTypes {
export enum ResponseType {
Basic,
Cors,
Default,
Expand Down
20 changes: 10 additions & 10 deletions modules/angular2/src/http/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {RequestOptionsArgs, Connection, ConnectionBackend} from './interfaces';
import {Request} from './static_request';
import {Response} from './static_response';
import {BaseRequestOptions, RequestOptions} from './base_request_options';
import {RequestMethods} from './enums';
import {RequestMethod} from './enums';
import {Observable} from 'angular2/core';

function httpRequest(backend: ConnectionBackend, request: Request): Observable<Response> {
Expand Down Expand Up @@ -103,7 +103,7 @@ export class Http {
if (isString(url)) {
responseObservable = httpRequest(
this._backend,
new Request(mergeOptions(this._defaultOptions, options, RequestMethods.Get, url)));
new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Get, url)));
} else if (url instanceof Request) {
responseObservable = httpRequest(this._backend, url);
} else {
Expand All @@ -117,7 +117,7 @@ export class Http {
*/
get(url: string, options?: RequestOptionsArgs): Observable<Response> {
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
RequestMethods.Get, url)));
RequestMethod.Get, url)));
}

/**
Expand All @@ -127,7 +127,7 @@ export class Http {
return httpRequest(
this._backend,
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
options, RequestMethods.Post, url)));
options, RequestMethod.Post, url)));
}

/**
Expand All @@ -137,15 +137,15 @@ export class Http {
return httpRequest(
this._backend,
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
options, RequestMethods.Put, url)));
options, RequestMethod.Put, url)));
}

/**
* Performs a request with `delete` http method.
*/
delete (url: string, options?: RequestOptionsArgs): Observable<Response> {
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
RequestMethods.Delete, url)));
RequestMethod.Delete, url)));
}

/**
Expand All @@ -155,15 +155,15 @@ export class Http {
return httpRequest(
this._backend,
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
options, RequestMethods.Patch, url)));
options, RequestMethod.Patch, url)));
}

/**
* Performs a request with `head` http method.
*/
head(url: string, options?: RequestOptionsArgs): Observable<Response> {
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
RequestMethods.Head, url)));
RequestMethod.Head, url)));
}
}

Expand All @@ -182,10 +182,10 @@ export class Jsonp extends Http {
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
var responseObservable: any;
if (isString(url)) {
url = new Request(mergeOptions(this._defaultOptions, options, RequestMethods.Get, url));
url = new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Get, url));
}
if (url instanceof Request) {
if (url.method !== RequestMethods.Get) {
if (url.method !== RequestMethod.Get) {
makeTypeError('JSONP requests must use GET request method.');
}
responseObservable = httpRequest(this._backend, url);
Expand Down
Loading
X Tutup