Skip to content

Commit e68e69e

Browse files
committed
refactor(Http): rename request options interface
1 parent 70ffd26 commit e68e69e

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

modules/angular2/src/http/base_request_options.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ import {CONST_EXPR, CONST, isPresent} from 'angular2/src/facade/lang';
22
import {Headers} from './headers';
33
import {URLSearchParams} from './url_search_params';
44
import {RequestModesOpts, RequestMethods, RequestCacheOpts, RequestCredentialsOpts} from './enums';
5-
import {RequestOptions} from './interfaces';
5+
import {IRequestOptions} from './interfaces';
66
import {Injectable} from 'angular2/di';
77
import {ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
88

9-
export class RequestOptionsClass implements RequestOptions {
9+
export class RequestOptions implements IRequestOptions {
1010
method: RequestMethods = RequestMethods.GET;
1111
headers: Headers;
1212
body: URLSearchParams | FormData | Blob | string;
1313
mode: RequestModesOpts = RequestModesOpts.Cors;
1414
credentials: RequestCredentialsOpts;
1515
cache: RequestCacheOpts;
16-
constructor({method, headers, body, mode, credentials,
17-
cache}: RequestOptions = {method: RequestMethods.GET, mode: RequestModesOpts.Cors}) {
16+
constructor({method, headers, body, mode, credentials, cache}: IRequestOptions = {
17+
method: RequestMethods.GET,
18+
mode: RequestModesOpts.Cors
19+
}) {
1820
this.method = method;
1921
this.headers = headers;
2022
this.body = body;
@@ -23,12 +25,12 @@ export class RequestOptionsClass implements RequestOptions {
2325
this.cache = cache;
2426
}
2527

26-
merge(opts: RequestOptions = {}): RequestOptionsClass {
27-
return new RequestOptionsClass(StringMapWrapper.merge(this, opts));
28+
merge(opts: IRequestOptions = {}): RequestOptions {
29+
return new RequestOptions(StringMapWrapper.merge(this, opts));
2830
}
2931
}
3032

3133
@Injectable()
32-
export class BaseRequestOptions extends RequestOptionsClass {
34+
export class BaseRequestOptions extends RequestOptions {
3335
constructor() { super(); }
3436
}

modules/angular2/src/http/http.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference path="../../typings/rx/rx.all.d.ts" />
22

33
import {Injectable} from 'angular2/src/di/decorators';
4-
import {RequestOptions, Connection} from './interfaces';
4+
import {IRequestOptions, Connection} from './interfaces';
55
import {Request} from './static_request';
66
import {Response} from './static_response';
77
import {XHRBackend} from './backends/xhr_backend';
@@ -61,44 +61,44 @@ function httpRequest(backend: XHRBackend, request: Request) {
6161
export class Http {
6262
constructor(private backend: XHRBackend, private defaultOptions: BaseRequestOptions) {}
6363

64-
request(url: string|Request, options?: RequestOptions): Rx.Observable<Response> {
64+
request(url: string | Request, options?: IRequestOptions): Rx.Observable<Response> {
6565
if (typeof url === 'string') {
6666
return httpRequest(this.backend, new Request(url, this.defaultOptions.merge(options)));
6767
} else if (url instanceof Request) {
6868
return httpRequest(this.backend, url);
6969
}
7070
}
7171

72-
get(url: string, options?: RequestOptions) {
72+
get(url: string, options?: IRequestOptions) {
7373
return httpRequest(this.backend, new Request(url, this.defaultOptions.merge(options)
7474
.merge({method: RequestMethods.GET})));
7575
}
7676

77-
post(url: string, body: URLSearchParams | FormData | Blob | string, options?: RequestOptions) {
77+
post(url: string, body: URLSearchParams | FormData | Blob | string, options?: IRequestOptions) {
7878
return httpRequest(this.backend,
7979
new Request(url, this.defaultOptions.merge(options)
8080

8181
.merge({body: body, method: RequestMethods.POST})));
8282
}
8383

84-
put(url: string, body: URLSearchParams | FormData | Blob | string, options?: RequestOptions) {
84+
put(url: string, body: URLSearchParams | FormData | Blob | string, options?: IRequestOptions) {
8585
return httpRequest(this.backend,
8686
new Request(url, this.defaultOptions.merge(options)
8787
.merge({body: body, method: RequestMethods.PUT})));
8888
}
8989

90-
delete (url: string, options?: RequestOptions) {
90+
delete (url: string, options?: IRequestOptions) {
9191
return httpRequest(this.backend, new Request(url, this.defaultOptions.merge(options)
9292
.merge({method: RequestMethods.DELETE})));
9393
}
9494

95-
patch(url: string, body: URLSearchParams | FormData | Blob | string, options?: RequestOptions) {
95+
patch(url: string, body: URLSearchParams | FormData | Blob | string, options?: IRequestOptions) {
9696
return httpRequest(this.backend,
9797
new Request(url, this.defaultOptions.merge(options)
9898
.merge({body: body, method: RequestMethods.PATCH})));
9999
}
100100

101-
head(url: string, options?: RequestOptions) {
101+
head(url: string, options?: IRequestOptions) {
102102
return httpRequest(this.backend, new Request(url, this.defaultOptions.merge(options)
103103
.merge({method: RequestMethods.HEAD})));
104104
}
@@ -111,7 +111,7 @@ if (Rx.hasOwnProperty('default')) {
111111
Observable = Rx.Observable;
112112
}
113113
export function HttpFactory(backend: XHRBackend, defaultOptions: BaseRequestOptions) {
114-
return function(url: string | Request, options?: RequestOptions) {
114+
return function(url: string | Request, options?: IRequestOptions) {
115115
if (typeof url === 'string') {
116116
return httpRequest(backend, new Request(url, defaultOptions.merge(options)));
117117
} else if (url instanceof Request) {

modules/angular2/src/http/interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import {Headers} from './headers';
1212
import {URLSearchParams} from './url_search_params';
1313

14-
export interface RequestOptions {
14+
export interface IRequestOptions {
1515
method?: RequestMethods;
1616
headers?: Headers;
1717
body?: URLSearchParams | FormData | Blob | string;
@@ -60,4 +60,4 @@ export interface Connection {
6060

6161
// Prefixed as IHttp because used in conjunction with Http class, but interface is callable
6262
// constructor(@Inject(Http) http:IHttp)
63-
export interface IHttp { (url: string, options?: RequestOptions): Rx.Observable<Response> }
63+
export interface IHttp { (url: string, options?: IRequestOptions): Rx.Observable<Response> }

modules/angular2/src/http/static_request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {RequestMethods, RequestModesOpts, RequestCredentialsOpts} from './enums';
22
import {URLSearchParams} from './url_search_params';
3-
import {RequestOptions, Request as IRequest} from './interfaces';
3+
import {IRequestOptions, Request as IRequest} from './interfaces';
44
import {Headers} from './headers';
55
import {BaseException, RegExpWrapper} from 'angular2/src/facade/lang';
66

@@ -21,7 +21,7 @@ export class Request implements IRequest {
2121

2222
constructor(public url: string, {body, method = RequestMethods.GET, mode = RequestModesOpts.Cors,
2323
credentials = RequestCredentialsOpts.Omit,
24-
headers = new Headers()}: RequestOptions = {}) {
24+
headers = new Headers()}: IRequestOptions = {}) {
2525
this.body = body;
2626
// Defaults to 'GET', consistent with browser
2727
this.method = method;

modules/angular2/test/http/http_spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,8 @@ export function main() {
124124

125125
it('should accept a fully-qualified request as its only parameter', () => {
126126
var req = new Request('https://google.com');
127-
backend.connections.subscribe(c => {
128-
expect(c.request.url).toBe('https://google.com');
129-
});
130-
http.request(req).subscribe(() =>{});
127+
backend.connections.subscribe(c => { expect(c.request.url).toBe('https://google.com'); });
128+
http.request(req).subscribe(() => {});
131129
});
132130
});
133131

0 commit comments

Comments
 (0)