Skip to content

Commit 146dbf1

Browse files
committed
refactor(Http): remove HttpFactory
BREAKING CHANGE: HttpFactory is no longer available. This factory provided a function alternative to the `request` method of the Http class, but added no real value. The additional factory required an additional IHttp interface, an odd way to inject while preserving type information (`@Inject(HttpFactory) http:IHttp`), and required additional documentation in the http module. Closes #2564
1 parent 55bf0e5 commit 146dbf1

File tree

4 files changed

+6
-118
lines changed

4 files changed

+6
-118
lines changed

modules/angular2/http.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* class.
77
*/
88
import {bind, Binding} from 'angular2/di';
9-
import {Http, HttpFactory} from './src/http/http';
9+
import {Http} from './src/http/http';
1010
import {XHRBackend, XHRConnection} from 'angular2/src/http/backends/xhr_backend';
1111
import {BrowserXHR} from 'angular2/src/http/backends/browser_xhr';
1212
import {BaseRequestOptions, RequestOptions} from 'angular2/src/http/base_request_options';
@@ -17,7 +17,6 @@ export {Request} from 'angular2/src/http/static_request';
1717
export {Response} from 'angular2/src/http/static_response';
1818

1919
export {
20-
IHttp,
2120
IRequestOptions,
2221
IResponse,
2322
Connection,
@@ -26,7 +25,7 @@ export {
2625

2726
export {BaseRequestOptions, RequestOptions} from 'angular2/src/http/base_request_options';
2827
export {XHRBackend, XHRConnection} from 'angular2/src/http/backends/xhr_backend';
29-
export {Http, HttpFactory} from './src/http/http';
28+
export {Http} from './src/http/http';
3029

3130
export {Headers} from 'angular2/src/http/headers';
3231

@@ -50,12 +49,5 @@ export {URLSearchParams} from 'angular2/src/http/url_search_params';
5049
* ```
5150
*
5251
*/
53-
export var httpInjectables: List<any> = [
54-
bind(ConnectionBackend)
55-
.toClass(XHRBackend),
56-
BrowserXHR,
57-
XHRBackend,
58-
BaseRequestOptions,
59-
bind(HttpFactory).toFactory(HttpFactory, [XHRBackend, BaseRequestOptions]),
60-
Http
61-
];
52+
export var httpInjectables: List<any> =
53+
[bind(ConnectionBackend).toClass(XHRBackend), BrowserXHR, XHRBackend, BaseRequestOptions, Http];

modules/angular2/src/http/http.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -144,36 +144,3 @@ export class Http {
144144
RequestMethods.HEAD, url)));
145145
}
146146
}
147-
148-
/**
149-
*
150-
* Alias to the `request` method of {@link Http}, for those who'd prefer a simple function instead
151-
* of an object. In order to get TypeScript type information about the `HttpFactory`, the {@link
152-
* IHttp} interface can be used as shown in the following example.
153-
*
154-
* #Example
155-
*
156-
* ```
157-
* import {httpInjectables, HttpFactory, IHttp} from 'angular2/http';
158-
* @Component({
159-
* appInjector: [httpInjectables]
160-
* })
161-
* @View({
162-
* templateUrl: 'people.html'
163-
* })
164-
* class MyComponent {
165-
* constructor(@Inject(HttpFactory) http:IHttp) {
166-
* http('people.json').subscribe(res => this.people = res.json());
167-
* }
168-
* }
169-
* ```
170-
**/
171-
export function HttpFactory(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
172-
return function(url: string | Request, options?: IRequestOptions) {
173-
if (isString(url)) {
174-
return httpRequest(backend, new Request(mergeOptions(defaultOptions, options, null, url)));
175-
} else if (url instanceof Request) {
176-
return httpRequest(backend, url);
177-
}
178-
};
179-
}

modules/angular2/src/http/interfaces.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,33 +55,8 @@ export interface IResponse {
5555
url: string;
5656
totalBytes: number;
5757
bytesLoaded: number;
58-
blob(): any; // TODO: Blob
58+
blob(): any; // TODO: Blob
5959
arrayBuffer(): any; // TODO: ArrayBuffer
6060
text(): string;
6161
json(): Object;
6262
}
63-
64-
/**
65-
* Provides an interface to provide type information for {@link HttpFactory} when injecting.
66-
*
67-
* #Example
68-
*
69-
* ```
70-
* * import {httpInjectables, HttpFactory, IHttp} from 'angular2/http';
71-
* @Component({
72-
* appInjector: [httpInjectables]
73-
* })
74-
* @View({
75-
* templateUrl: 'people.html'
76-
* })
77-
* class MyComponent {
78-
* constructor(@Inject(HttpFactory) http:IHttp) {
79-
* http('people.json').subscribe(res => this.people = res.json());
80-
* }
81-
* }
82-
* ```
83-
*
84-
*/
85-
// Prefixed as IHttp because used in conjunction with Http class, but interface is callable
86-
// constructor(@Inject(Http) http:IHttp)
87-
export interface IHttp { (url: string, options?: IRequestOptions): EventEmitter }

modules/angular2/test/http/http_spec.ts

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
xit,
1212
SpyObject
1313
} from 'angular2/test_lib';
14-
import {Http, HttpFactory} from 'angular2/src/http/http';
14+
import {Http} from 'angular2/src/http/http';
1515
import {Injector, bind} from 'angular2/di';
1616
import {MockBackend} from 'angular2/src/http/backends/mock_backend';
1717
import {Response} from 'angular2/src/http/static_response';
@@ -40,69 +40,23 @@ export function main() {
4040
var injector: Injector;
4141
var backend: MockBackend;
4242
var baseResponse;
43-
var httpFactory;
4443
beforeEach(() => {
4544
injector = Injector.resolveAndCreate([
4645
BaseRequestOptions,
4746
MockBackend,
48-
bind(ConnectionBackend).toClass(MockBackend),
49-
bind(HttpFactory).toFactory(HttpFactory, [MockBackend, BaseRequestOptions]),
5047
bind(Http).toFactory(
5148
function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
5249
return new Http(backend, defaultOptions);
5350
},
5451
[MockBackend, BaseRequestOptions])
5552
]);
5653
http = injector.get(Http);
57-
httpFactory = injector.get(HttpFactory);
5854
backend = injector.get(MockBackend);
5955
baseResponse = new Response({body: 'base response'});
6056
});
6157

6258
afterEach(() => backend.verifyNoPendingRequests());
6359

64-
describe('HttpFactory', () => {
65-
it('should return an Observable', () => {
66-
expect(ObservableWrapper.isObservable(httpFactory(url))).toBe(true);
67-
backend.resolveAllConnections();
68-
});
69-
70-
71-
it('should perform a get request for given url if only passed a string',
72-
inject([AsyncTestCompleter], (async) => {
73-
ObservableWrapper.subscribe(backend.connections, c => c.mockRespond(baseResponse));
74-
ObservableWrapper.subscribe(httpFactory('http://basic.connection'), res => {
75-
expect(res.text()).toBe('base response');
76-
async.done();
77-
});
78-
79-
}));
80-
81-
82-
it('should accept a fully-qualified request as its only parameter',
83-
inject([AsyncTestCompleter], (async) => {
84-
var req = new Request(new RequestOptions({url: 'https://google.com'}));
85-
ObservableWrapper.subscribe(backend.connections, c => {
86-
expect(c.request.url).toBe('https://google.com');
87-
c.mockRespond(new Response({body: 'Thank you'}));
88-
async.done();
89-
});
90-
ObservableWrapper.subscribe(httpFactory(req), (res) => {});
91-
}));
92-
93-
// TODO: make dart not complain about "argument type 'Map' cannot be assigned to the parameter
94-
// type 'IRequestOptions'"
95-
// xit('should perform a get request for given url if passed a dictionary',
96-
// inject([AsyncTestCompleter], async => {
97-
// ObservableWrapper.subscribe(backend.connections, c => c.mockRespond(baseResponse));
98-
// ObservableWrapper.subscribe(httpFactory(url, {method: RequestMethods.GET}), res => {
99-
// expect(res.text()).toBe('base response');
100-
// async.done();
101-
// });
102-
// }));
103-
});
104-
105-
10660
describe('Http', () => {
10761
describe('.request()', () => {
10862
it('should return an Observable',

0 commit comments

Comments
 (0)