X Tutup
Skip to content

Commit a9b1270

Browse files
committed
fix(http): use Observable<Response> on Http methods
use correct type definitions for Http responses. Closes angular#5017
1 parent 31687ef commit a9b1270

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

modules/angular2/src/http/backends/jsonp_backend.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@ import {Response} from '../static_response';
55
import {ResponseOptions, BaseResponseOptions} from '../base_response_options';
66
import {Injectable} from 'angular2/angular2';
77
import {BrowserJsonp} from './browser_jsonp';
8-
import {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async';
98
import {makeTypeError} from 'angular2/src/core/facade/exceptions';
109
import {StringWrapper, isPresent} from 'angular2/src/core/facade/lang';
11-
// todo(robwormald): temporary until https://github.com/angular/angular/issues/4390 decided
12-
var Rx = require('@reactivex/rxjs/dist/cjs/Rx');
13-
var {Observable} = Rx;
10+
import {Observable} from 'angular2/angular2';
1411

1512
const JSONP_ERR_NO_CALLBACK = 'JSONP injected script did not invoke callback.';
1613
const JSONP_ERR_WRONG_METHOD = 'JSONP requests must use GET request method.';
1714

1815
export abstract class JSONPConnection implements Connection {
1916
readyState: ReadyStates;
2017
request: Request;
21-
response: any;
18+
response: Observable<Response>;
2219
abstract finished(data?: any): void;
2320
}
2421

modules/angular2/src/http/backends/xhr_backend.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import {ResponseOptions, BaseResponseOptions} from '../base_response_options';
66
import {Injectable} from 'angular2/angular2';
77
import {BrowserXhr} from './browser_xhr';
88
import {isPresent} from 'angular2/src/core/facade/lang';
9-
// todo(robwormald): temporary until https://github.com/angular/angular/issues/4390 decided
10-
var Rx = require('@reactivex/rxjs/dist/cjs/Rx');
11-
var {Observable} = Rx;
9+
import {Observable} from 'angular2/angular2';
1210
/**
1311
* Creates connections using `XMLHttpRequest`. Given a fully-qualified
1412
* request, an `XHRConnection` will immediately create an `XMLHttpRequest` object and send the
@@ -23,7 +21,7 @@ export class XHRConnection implements Connection {
2321
* Response {@link EventEmitter} which emits a single {@link Response} value on load event of
2422
* `XMLHttpRequest`.
2523
*/
26-
response: any; // TODO: Make generic of <Response>;
24+
response: Observable<Response>;
2725
readyState: ReadyStates;
2826
constructor(req: Request, browserXHR: BrowserXhr, baseResponseOptions?: ResponseOptions) {
2927
this.request = req;

modules/angular2/src/http/http.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import {makeTypeError} from 'angular2/src/core/facade/exceptions';
33
import {Injectable} from 'angular2/angular2';
44
import {RequestOptionsArgs, Connection, ConnectionBackend} from './interfaces';
55
import {Request} from './static_request';
6+
import {Response} from './static_response';
67
import {BaseRequestOptions, RequestOptions} from './base_request_options';
78
import {RequestMethods} from './enums';
9+
import {Observable} from 'angular2/angular2';
810

9-
function httpRequest(backend: ConnectionBackend, request: Request): any {
11+
function httpRequest(backend: ConnectionBackend, request: Request): Observable<Response> {
1012
return backend.createConnection(request).response;
1113
}
1214

@@ -96,7 +98,7 @@ export class Http {
9698
* object can be provided as the 2nd argument. The options object will be merged with the values
9799
* of {@link BaseRequestOptions} before performing the request.
98100
*/
99-
request(url: string | Request, options?: RequestOptionsArgs): any {
101+
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
100102
var responseObservable: any;
101103
if (isString(url)) {
102104
responseObservable = httpRequest(
@@ -113,15 +115,15 @@ export class Http {
113115
/**
114116
* Performs a request with `get` http method.
115117
*/
116-
get(url: string, options?: RequestOptionsArgs): any {
118+
get(url: string, options?: RequestOptionsArgs): Observable<Response> {
117119
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
118120
RequestMethods.Get, url)));
119121
}
120122

121123
/**
122124
* Performs a request with `post` http method.
123125
*/
124-
post(url: string, body: string, options?: RequestOptionsArgs): any {
126+
post(url: string, body: string, options?: RequestOptionsArgs): Observable<Response> {
125127
return httpRequest(
126128
this._backend,
127129
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
@@ -131,7 +133,7 @@ export class Http {
131133
/**
132134
* Performs a request with `put` http method.
133135
*/
134-
put(url: string, body: string, options?: RequestOptionsArgs): any {
136+
put(url: string, body: string, options?: RequestOptionsArgs): Observable<Response> {
135137
return httpRequest(
136138
this._backend,
137139
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
@@ -141,15 +143,15 @@ export class Http {
141143
/**
142144
* Performs a request with `delete` http method.
143145
*/
144-
delete (url: string, options?: RequestOptionsArgs): any {
146+
delete (url: string, options?: RequestOptionsArgs): Observable<Response> {
145147
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
146148
RequestMethods.Delete, url)));
147149
}
148150

149151
/**
150152
* Performs a request with `patch` http method.
151153
*/
152-
patch(url: string, body: string, options?: RequestOptionsArgs): any {
154+
patch(url: string, body: string, options?: RequestOptionsArgs): Observable<Response> {
153155
return httpRequest(
154156
this._backend,
155157
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
@@ -159,7 +161,7 @@ export class Http {
159161
/**
160162
* Performs a request with `head` http method.
161163
*/
162-
head(url: string, options?: RequestOptionsArgs): any {
164+
head(url: string, options?: RequestOptionsArgs): Observable<Response> {
163165
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
164166
RequestMethods.Head, url)));
165167
}
@@ -177,7 +179,7 @@ export class Jsonp extends Http {
177179
* object can be provided as the 2nd argument. The options object will be merged with the values
178180
* of {@link BaseRequestOptions} before performing the request.
179181
*/
180-
request(url: string | Request, options?: RequestOptionsArgs): any {
182+
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
181183
var responseObservable: any;
182184
if (isString(url)) {
183185
url = new Request(mergeOptions(this._defaultOptions, options, RequestMethods.Get, url));

0 commit comments

Comments
 (0)
X Tutup