chore: Make enum names consistent with TypeScript convention

BREAKING_CHANGE

Ts2Dart issue: https://github.com/angular/ts2dart/issues/270
TypeScript convention: https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines
DartConvertion: https://www.dartlang.org/articles/style-guide/

Rename:

- NumberFormatStyle.DECIMAL => NumberFormatStyle.Decimal
- NumberFormatStyle.PERCENT => NumberFormatStyle.Percent
- NumberFormatStyle.CURRENCY => NumberFormatStyle.Currency
- RequestMethods.GET => RequestMethods.Get
- RequestMethods.POST => RequestMethods.Post
- RequestMethods.PUT => RequestMethods.Put
- RequestMethods.DELETE => RequestMethods.Delete
- RequestMethods.HEAD => RequestMethods.Head
- RequestMethods.PATCH => RequestMethods.Patch
- ReadyStates.UNSENT => ReadyStates.Unsent
- ReadyStates.OPEN => ReadyStates.Open
- ReadyStates.HEADERS_RECEIVED => ReadyStates.HeadersReceived
- ReadyStates.LOADING => ReadyStates.Loading
- ReadyStates.DONE => ReadyStates.Done
- ReadyStates.CANCELLED => ReadyStates.Canceled
This commit is contained in:
Misko Hevery
2015-08-26 13:40:12 -07:00
parent 465f7c95b0
commit 37b042b361
23 changed files with 206 additions and 209 deletions

View File

@ -19,12 +19,12 @@ export class JSONPConnection implements Connection {
constructor(req: Request, private _dom: BrowserJsonp,
private baseResponseOptions?: ResponseOptions) {
if (req.method !== RequestMethods.GET) {
if (req.method !== RequestMethods.Get) {
throw makeTypeError("JSONP requests must use GET request method.");
}
this.request = req;
this.response = new EventEmitter();
this.readyState = ReadyStates.LOADING;
this.readyState = ReadyStates.Loading;
this._id = _dom.nextRequestID();
_dom.exposeConnection(this._id, this);
@ -42,8 +42,8 @@ export class JSONPConnection implements Connection {
let script = this._script = _dom.build(url);
script.addEventListener('load', (event) => {
if (this.readyState === ReadyStates.CANCELLED) return;
this.readyState = ReadyStates.DONE;
if (this.readyState === ReadyStates.Cancelled) return;
this.readyState = ReadyStates.Done;
_dom.cleanup(script);
if (!this._finished) {
ObservableWrapper.callThrow(
@ -60,8 +60,8 @@ export class JSONPConnection implements Connection {
});
script.addEventListener('error', (error) => {
if (this.readyState === ReadyStates.CANCELLED) return;
this.readyState = ReadyStates.DONE;
if (this.readyState === ReadyStates.Cancelled) return;
this.readyState = ReadyStates.Done;
_dom.cleanup(script);
ObservableWrapper.callThrow(this.response, error);
});
@ -73,12 +73,12 @@ export class JSONPConnection implements Connection {
// Don't leak connections
this._finished = true;
this._dom.removeConnection(this._id);
if (this.readyState === ReadyStates.CANCELLED) return;
if (this.readyState === ReadyStates.Cancelled) return;
this._responseData = data;
}
dispose(): void {
this.readyState = ReadyStates.CANCELLED;
this.readyState = ReadyStates.Cancelled;
let script = this._script;
this._script = null;
if (isPresent(script)) {

View File

@ -34,7 +34,7 @@ export class MockConnection implements Connection {
constructor(req: Request) {
this.response = new EventEmitter();
this.readyState = ReadyStates.OPEN;
this.readyState = ReadyStates.Open;
this.request = req;
}
@ -42,8 +42,8 @@ export class MockConnection implements Connection {
* Changes the `readyState` of the connection to a custom state of 5 (cancelled).
*/
dispose() {
if (this.readyState !== ReadyStates.DONE) {
this.readyState = ReadyStates.CANCELLED;
if (this.readyState !== ReadyStates.Done) {
this.readyState = ReadyStates.Cancelled;
}
}
@ -62,10 +62,10 @@ export class MockConnection implements Connection {
*
*/
mockRespond(res: Response) {
if (this.readyState === ReadyStates.DONE || this.readyState === ReadyStates.CANCELLED) {
if (this.readyState === ReadyStates.Done || this.readyState === ReadyStates.Cancelled) {
throw new BaseException('Connection has already been resolved');
}
this.readyState = ReadyStates.DONE;
this.readyState = ReadyStates.Done;
ObservableWrapper.callNext(this.response, res);
ObservableWrapper.callReturn(this.response);
}
@ -91,7 +91,7 @@ export class MockConnection implements Connection {
*/
mockError(err?: Error) {
// Matches XHR semantics
this.readyState = ReadyStates.DONE;
this.readyState = ReadyStates.Done;
ObservableWrapper.callThrow(this.response, err);
ObservableWrapper.callReturn(this.response);
}

View File

@ -31,7 +31,7 @@ export class XHRConnection implements Connection {
this.response = new EventEmitter();
this._xhr = browserXHR.build();
// TODO(jeffbcross): implement error listening/propagation
this._xhr.open(RequestMethods[req.method], req.url);
this._xhr.open(RequestMethods[req.method].toUpperCase(), 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)

View File

@ -92,6 +92,6 @@ export class RequestOptions {
@Injectable()
export class BaseRequestOptions extends RequestOptions {
constructor() {
super({method: RequestMethods.GET, headers: new Headers(), mode: RequestModesOpts.Cors});
super({method: RequestMethods.Get, headers: new Headers(), mode: RequestModesOpts.Cors});
}
}

View File

@ -37,13 +37,13 @@ export enum RequestCredentialsOpts {
* Supported http methods.
*/
export enum RequestMethods {
GET,
POST,
PUT,
DELETE,
OPTIONS,
HEAD,
PATCH
Get,
Post,
Put,
Delete,
Options,
Head,
Patch
}
/**
@ -52,12 +52,12 @@ export enum RequestMethods {
* additional "CANCELLED" state.
*/
export enum ReadyStates {
UNSENT,
OPEN,
HEADERS_RECEIVED,
LOADING,
DONE,
CANCELLED
Unsent,
Open,
HeadersReceived,
Loading,
Done,
Cancelled
}
/**

View File

@ -116,7 +116,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, RequestMethods.Get, url)));
} else if (url instanceof Request) {
responseObservable = httpRequest(this._backend, url);
}
@ -128,7 +128,7 @@ export class Http {
*/
get(url: string, options?: RequestOptionsArgs): EventEmitter {
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
RequestMethods.GET, url)));
RequestMethods.Get, url)));
}
/**
@ -138,7 +138,7 @@ export class Http {
return httpRequest(
this._backend,
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
options, RequestMethods.POST, url)));
options, RequestMethods.Post, url)));
}
/**
@ -148,7 +148,7 @@ export class Http {
return httpRequest(
this._backend,
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
options, RequestMethods.PUT, url)));
options, RequestMethods.Put, url)));
}
/**
@ -156,7 +156,7 @@ export class Http {
*/
delete (url: string, options?: RequestOptionsArgs): EventEmitter {
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
RequestMethods.DELETE, url)));
RequestMethods.Delete, url)));
}
/**
@ -166,7 +166,7 @@ export class Http {
return httpRequest(
this._backend,
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
options, RequestMethods.PATCH, url)));
options, RequestMethods.Patch, url)));
}
/**
@ -174,7 +174,7 @@ export class Http {
*/
head(url: string, options?: RequestOptionsArgs): EventEmitter {
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
RequestMethods.HEAD, url)));
RequestMethods.Head, url)));
}
}
@ -193,10 +193,10 @@ export class Jsonp extends Http {
request(url: string | Request, options?: RequestOptionsArgs): EventEmitter {
var responseObservable: EventEmitter;
if (isString(url)) {
url = new Request(mergeOptions(this._defaultOptions, options, RequestMethods.GET, url));
url = new Request(mergeOptions(this._defaultOptions, options, RequestMethods.Get, url));
}
if (url instanceof Request) {
if (url.method !== RequestMethods.GET) {
if (url.method !== RequestMethods.Get) {
makeTypeError('JSONP requests must use GET request method.');
}
responseObservable = httpRequest(this._backend, url);