From 51285666d851e229d2f33ddac3494884b8a58f87 Mon Sep 17 00:00:00 2001 From: Richard Sentino Date: Wed, 26 Aug 2015 14:26:13 +1200 Subject: [PATCH] chore(http): remove RequestMethodsMap This class was only added to do a reverse lookup of RequestMethods enum to get its name (i.e. "GET") for Dart. Since Dart is no longer supported by Http, method names can just be retrieved with TypeScript's support for enum name lookup, i.e. RequestMethods[RequestMethods.GET] === 'GET', making the RequestMethodsMap utility obsolete. Closes #2904 --- modules/angular2/src/http/backends/jsonp_backend.ts | 2 +- modules/angular2/src/http/backends/xhr_backend.ts | 7 ++----- modules/angular2/src/http/enums.ts | 7 ------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/modules/angular2/src/http/backends/jsonp_backend.ts b/modules/angular2/src/http/backends/jsonp_backend.ts index 3cfbb29466..9ef2a8fa6c 100644 --- a/modules/angular2/src/http/backends/jsonp_backend.ts +++ b/modules/angular2/src/http/backends/jsonp_backend.ts @@ -1,5 +1,5 @@ import {ConnectionBackend, Connection} from '../interfaces'; -import {ReadyStates, RequestMethods, RequestMethodsMap} from '../enums'; +import {ReadyStates, RequestMethods} from '../enums'; import {Request} from '../static_request'; import {Response} from '../static_response'; import {ResponseOptions, BaseResponseOptions} from '../base_response_options'; diff --git a/modules/angular2/src/http/backends/xhr_backend.ts b/modules/angular2/src/http/backends/xhr_backend.ts index e5096520ac..3722382474 100644 --- a/modules/angular2/src/http/backends/xhr_backend.ts +++ b/modules/angular2/src/http/backends/xhr_backend.ts @@ -1,5 +1,5 @@ import {ConnectionBackend, Connection} from '../interfaces'; -import {ReadyStates, RequestMethods, RequestMethodsMap, ResponseTypes} from '../enums'; +import {ReadyStates, RequestMethods, ResponseTypes} from '../enums'; import {Request} from '../static_request'; import {Response} from '../static_response'; import {ResponseOptions, BaseResponseOptions} from '../base_response_options'; @@ -27,14 +27,11 @@ export class XHRConnection implements Connection { private _xhr; // TODO: make type XMLHttpRequest, pending resolution of // https://github.com/angular/ts2dart/issues/230 constructor(req: Request, browserXHR: BrowserXhr, baseResponseOptions?: ResponseOptions) { - // TODO: get rid of this when enum lookups are available in ts2dart - // https://github.com/angular/ts2dart/issues/221 - var requestMethodsMap = new RequestMethodsMap(); this.request = req; this.response = new EventEmitter(); this._xhr = browserXHR.build(); // TODO(jeffbcross): implement error listening/propagation - this._xhr.open(requestMethodsMap.getMethod(ENUM_INDEX(req.method)), req.url); + this._xhr.open(RequestMethods[ENUM_INDEX(req.method)], req.url); this._xhr.addEventListener('load', (_) => { // responseText is the old-school way of retrieving response (supported by IE8 & 9) // response/responseType properties were introduced in XHR Level2 spec (supported by IE10) diff --git a/modules/angular2/src/http/enums.ts b/modules/angular2/src/http/enums.ts index efdc8b6c78..1e0183ba66 100644 --- a/modules/angular2/src/http/enums.ts +++ b/modules/angular2/src/http/enums.ts @@ -46,13 +46,6 @@ export enum RequestMethods { PATCH } -// TODO: Remove this when enum lookups are available in ts2dart -// https://github.com/angular/ts2dart/issues/221 -export class RequestMethodsMap { - private _methods: List; - constructor() { this._methods = ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD', 'PATCH']; } - getMethod(method: number): string { return this._methods[method]; } -} /** * All possible states in which a connection can be, based on * [States](http://www.w3.org/TR/XMLHttpRequest/#states) from the `XMLHttpRequest` spec, but with an