Skip to content

Commit

Permalink
chore: Remove IRequestOptions / IResponseOptions
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

Reasons:

1) Interfaces should not start with letter ‘I’
2) Interfaces do not help with mistype properties, but literal types do.
   - microsoft/TypeScript#3823
   - https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#strict-object-literal-assignment-checking
  • Loading branch information
mhevery committed Aug 13, 2015
1 parent 3e06a50 commit 7f2b413
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions modules/http/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export {Request} from 'http/src/static_request';
export {Response} from 'http/src/static_response';

export {
IRequestOptions,
IResponseOptions,
RequestOptionsArgs,
ResponseOptionsArgs,
Connection,
ConnectionBackend
} from 'http/src/interfaces';
Expand Down
8 changes: 4 additions & 4 deletions modules/http/src/base_request_options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {CONST_EXPR, CONST, isPresent, isString} from 'angular2/src/facade/lang';
import {Headers} from './headers';
import {RequestModesOpts, RequestMethods, RequestCacheOpts, RequestCredentialsOpts} from './enums';
import {IRequestOptions} from './interfaces';
import {RequestOptionsArgs} from './interfaces';
import {Injectable} from 'angular2/di';
import {URLSearchParams} from './url_search_params';

Expand All @@ -13,7 +13,7 @@ import {URLSearchParams} from './url_search_params';
*
* All values are null by default.
*/
export class RequestOptions implements IRequestOptions {
export class RequestOptions {
/**
* Http method with which to execute the request.
*
Expand All @@ -36,7 +36,7 @@ export class RequestOptions implements IRequestOptions {
url: string;
search: URLSearchParams;
constructor({method, headers, body, mode, credentials, cache, url, search}:
IRequestOptions = {}) {
RequestOptionsArgs = {}) {
this.method = isPresent(method) ? method : null;
this.headers = isPresent(headers) ? headers : null;
this.body = isPresent(body) ? body : null;
Expand All @@ -53,7 +53,7 @@ export class RequestOptions implements IRequestOptions {
* Creates a copy of the `RequestOptions` instance, using the optional input as values to override
* existing values.
*/
merge(options?: IRequestOptions): RequestOptions {
merge(options?: RequestOptionsArgs): RequestOptions {
return new RequestOptions({
method: isPresent(options) && isPresent(options.method) ? options.method : this.method,
headers: isPresent(options) && isPresent(options.headers) ? options.headers : this.headers,
Expand Down
8 changes: 4 additions & 4 deletions modules/http/src/base_response_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Injectable} from 'angular2/di';
import {isPresent, isJsObject} from 'angular2/src/facade/lang';
import {Headers} from './headers';
import {ResponseTypes} from './enums';
import {IResponseOptions} from './interfaces';
import {ResponseOptionsArgs} from './interfaces';

/**
* Creates a response options object similar to the
Expand All @@ -13,15 +13,15 @@ import {IResponseOptions} from './interfaces';
*
* All values are null by default.
*/
export class ResponseOptions implements IResponseOptions {
export class ResponseOptions {
// TODO: ArrayBuffer | FormData | Blob
body: string | Object;
status: number;
headers: Headers;
statusText: string;
type: ResponseTypes;
url: string;
constructor({body, status, headers, statusText, type, url}: IResponseOptions = {}) {
constructor({body, status, headers, statusText, type, url}: ResponseOptionsArgs = {}) {
this.body = isPresent(body) ? body : null;
this.status = isPresent(status) ? status : null;
this.headers = isPresent(headers) ? headers : null;
Expand All @@ -30,7 +30,7 @@ export class ResponseOptions implements IResponseOptions {
this.url = isPresent(url) ? url : null;
}

merge(options?: IResponseOptions): ResponseOptions {
merge(options?: ResponseOptionsArgs): ResponseOptions {
return new ResponseOptions({
body: isPresent(options) && isPresent(options.body) ? options.body : this.body,
status: isPresent(options) && isPresent(options.status) ? options.status : this.status,
Expand Down
18 changes: 9 additions & 9 deletions modules/http/src/http.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {isString, isPresent, isBlank, makeTypeError} from 'angular2/src/facade/lang';
import {Injectable} from 'angular2/src/di/decorators';
import {IRequestOptions, Connection, ConnectionBackend} from './interfaces';
import {RequestOptionsArgs, Connection, ConnectionBackend} from './interfaces';
import {Request} from './static_request';
import {BaseRequestOptions, RequestOptions} from './base_request_options';
import {RequestMethods} from './enums';
Expand Down Expand Up @@ -111,7 +111,7 @@ export class Http {
* object can be provided as the 2nd argument. The options object will be merged with the values
* of {@link BaseRequestOptions} before performing the request.
*/
request(url: string | Request, options?: IRequestOptions): EventEmitter {
request(url: string | Request, options?: RequestOptionsArgs): EventEmitter {
var responseObservable: EventEmitter;
if (isString(url)) {
responseObservable = httpRequest(
Expand All @@ -126,15 +126,15 @@ export class Http {
/**
* Performs a request with `get` http method.
*/
get(url: string, options?: IRequestOptions): EventEmitter {
get(url: string, options?: RequestOptionsArgs): EventEmitter {
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
RequestMethods.GET, url)));
}

/**
* Performs a request with `post` http method.
*/
post(url: string, body: string, options?: IRequestOptions): EventEmitter {
post(url: string, body: string, options?: RequestOptionsArgs): EventEmitter {
return httpRequest(
this._backend,
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
Expand All @@ -144,7 +144,7 @@ export class Http {
/**
* Performs a request with `put` http method.
*/
put(url: string, body: string, options?: IRequestOptions): EventEmitter {
put(url: string, body: string, options?: RequestOptionsArgs): EventEmitter {
return httpRequest(
this._backend,
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
Expand All @@ -154,15 +154,15 @@ export class Http {
/**
* Performs a request with `delete` http method.
*/
delete (url: string, options?: IRequestOptions): EventEmitter {
delete (url: string, options?: RequestOptionsArgs): EventEmitter {
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
RequestMethods.DELETE, url)));
}

/**
* Performs a request with `patch` http method.
*/
patch(url: string, body: string, options?: IRequestOptions): EventEmitter {
patch(url: string, body: string, options?: RequestOptionsArgs): EventEmitter {
return httpRequest(
this._backend,
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
Expand All @@ -172,7 +172,7 @@ export class Http {
/**
* Performs a request with `head` http method.
*/
head(url: string, options?: IRequestOptions): EventEmitter {
head(url: string, options?: RequestOptionsArgs): EventEmitter {
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
RequestMethods.HEAD, url)));
}
Expand All @@ -190,7 +190,7 @@ export class Jsonp extends Http {
* object can be provided as the 2nd argument. The options object will be merged with the values
* of {@link BaseRequestOptions} before performing the request.
*/
request(url: string | Request, options?: IRequestOptions): EventEmitter {
request(url: string | Request, options?: RequestOptionsArgs): EventEmitter {
var responseObservable: EventEmitter;
if (isString(url)) {
url = new Request(mergeOptions(this._defaultOptions, options, RequestMethods.GET, url));
Expand Down
4 changes: 2 additions & 2 deletions modules/http/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class Connection {
* Interface for options to construct a Request, based on
* [RequestInit](https://fetch.spec.whatwg.org/#requestinit) from the Fetch spec.
*/
export interface IRequestOptions {
export type RequestOptionsArgs = {
url?: string;
method?: RequestMethods;
search?: string | URLSearchParams;
Expand All @@ -58,7 +58,7 @@ export interface IRequestOptions {
* Interface for options to construct a Response, based on
* [ResponseInit](https://fetch.spec.whatwg.org/#responseinit) from the Fetch spec.
*/
export interface IResponseOptions {
export type ResponseOptionsArgs = {
// TODO: Support Blob, ArrayBuffer, JSON
body?: string | Object | FormData;
status?: number;
Expand Down

0 comments on commit 7f2b413

Please sign in to comment.