Skip to content

Commit f98bdce

Browse files
http methods return observables
1 parent ddfc138 commit f98bdce

File tree

7 files changed

+53
-35
lines changed

7 files changed

+53
-35
lines changed

angular2-polyfill/bundles/angular2-polyfill.d.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,18 @@ declare module "angular2-polyfill/src/http/interfaces/Response" {
168168
}
169169
}
170170
declare module "angular2-polyfill/src/http/http.service" {
171+
import { Observable } from 'rxjs';
171172
import { RequestOptionsArgs } from "angular2-polyfill/src/http/interfaces/RequestOptionsArgs";
172173
import { Response } from "angular2-polyfill/src/http/interfaces/Response";
173174
export class Http {
174175
private http;
175176
constructor(http: any);
176-
get(url: string, options?: RequestOptionsArgs): Promise<Response>;
177-
post(url: string, body: any, options?: RequestOptionsArgs): Promise<Response>;
178-
put(url: string, body: any, options?: RequestOptionsArgs): Promise<Response>;
179-
delete(url: string, options?: RequestOptionsArgs): Promise<Response>;
180-
patch(url: string, body: any, options?: RequestOptionsArgs): Promise<Response>;
181-
head(url: string, options?: RequestOptionsArgs): Promise<Response>;
177+
get(url: string, options?: RequestOptionsArgs): Observable<Response>;
178+
post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;
179+
put(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;
180+
delete(url: string, options?: RequestOptionsArgs): Observable<Response>;
181+
patch(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;
182+
head(url: string, options?: RequestOptionsArgs): Observable<Response>;
182183
}
183184
}
184185
declare module "angular2-polyfill/src/http/providers" {

angular2-polyfill/bundles/angular2-polyfill.js

+12-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular2-polyfill/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
"scripts": {
1515
"prepublish": "cd .. && npm run build"
1616
},
17+
"peerDependencies": {
18+
"reflect-metadata": "0.1.3",
19+
"rxjs": "5.0.0-beta.6"
20+
},
1721
"dependencies": {
1822
"camelcase": "^2.1.1",
1923
"decamelize": "^1.2.0",
+13-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {Observable} from 'rxjs';
12
import {Inject} from '../../core';
23
import {RequestOptionsArgs} from './interfaces/RequestOptionsArgs';
34
import {Response} from './interfaces/Response';
@@ -14,27 +15,27 @@ export class Http {
1415
//
1516
// }
1617

17-
get(url: string, options?: RequestOptionsArgs): Promise<Response> {
18-
return this.http.get(url, options);
18+
get(url: string, options?: RequestOptionsArgs): Observable<Response> {
19+
return Observable.fromPromise<Response>(this.http.get(url, options));
1920
}
2021

21-
post(url: string, body: any, options?: RequestOptionsArgs): Promise<Response> {
22-
return this.http.post(url, body, options);
22+
post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {
23+
return Observable.fromPromise<Response>(this.http.post(url, body, options));
2324
}
2425

25-
put(url: string, body: any, options?: RequestOptionsArgs): Promise<Response> {
26-
return this.http.put(url, body, options);
26+
put(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {
27+
return Observable.fromPromise<Response>(this.http.put(url, body, options));
2728
}
2829

29-
delete(url: string, options?: RequestOptionsArgs): Promise<Response> {
30-
return this.http.delete(url, options);
30+
delete(url: string, options?: RequestOptionsArgs): Observable<Response> {
31+
return Observable.fromPromise<Response>(this.http.delete(url, options));
3132
}
3233

33-
patch(url: string, body: any, options?: RequestOptionsArgs): Promise<Response> {
34-
return this.http.patch(url, body, options);
34+
patch(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {
35+
return Observable.fromPromise<Response>(this.http.patch(url, body, options));
3536
}
3637

37-
head(url: string, options?: RequestOptionsArgs): Promise<Response> {
38-
return this.http.head(url, options);
38+
head(url: string, options?: RequestOptionsArgs): Observable<Response> {
39+
return Observable.fromPromise<Response>(this.http.head(url, options));
3940
}
4041
}

angular2-polyfill/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"experimentalDecorators": true
99
},
1010
"exclude": [
11-
"bundles",
11+
"bundles",
12+
"node_modules",
1213
"typings/browser",
1314
"typings/browser.d.ts"
1415
]

gulpfile.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,22 @@ const ANGULAR2_POLYFILL_BUNDLE_CONFIG = [
1414

1515
const NG2_POLYFILL_BUNDLE_CONTENT = ANGULAR2_POLYFILL_BUNDLE_CONFIG.join(' + ');
1616

17+
const BASE = path.join(__dirname, 'angular2-polyfill');
18+
1719
const bundleConfig = {
20+
map: {
21+
'dot-prop': path.join(BASE, '/node_modules/dot-prop/index.js'),
22+
'is-obj': path.join(BASE, '/node_modules/is-obj/index.js'),
23+
'camelcase': path.join(BASE, '/node_modules/camelcase/index.js'),
24+
'decamelize': path.join(BASE, '/node_modules/decamelize/index.js'),
25+
'rxjs': path.join(BASE, '/node_modules/rxjs/Rx.js')
26+
},
27+
meta: {
28+
rxjs: {
29+
build: false
30+
}
31+
},
1832
paths: {
19-
'dot-prop': path.join(__dirname, '/node_modules/dot-prop/index.js'),
20-
'is-obj': path.join(__dirname, '/node_modules/is-obj/index.js'),
21-
'camelcase': path.join(__dirname, '/node_modules/camelcase/index.js'),
22-
'decamelize': path.join(__dirname, '/node_modules/decamelize/index.js'),
2333
'*': '*.js'
2434
}
2535
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"pub": "cd angular2-polyfill && npm publish",
1919
"typings": "cd angular2-polyfill && typings",
2020
"link": "cd angular2-polyfill && jspm link npm:angular2-polyfill@dev -y",
21-
"tsd-gen": "tsc -p angular2-polyfill --outFile angular2-polyfill/bundles/angular2-polyfill.js --module system -d --moduleResolution classic --rootDir \"./\""
21+
"tsd-gen": "tsc -p angular2-polyfill --outFile angular2-polyfill/bundles/angular2-polyfill.js --module system -d --moduleResolution node --rootDir \"./\""
2222
},
2323
"devDependencies": {
2424
"gulp": "^3.9.1",

0 commit comments

Comments
 (0)