Skip to content

Commit

Permalink
feat(ajax): adds ajax methods from rx-dom.
Browse files Browse the repository at this point in the history
  • Loading branch information
trxcllnt authored and benlesh committed Jan 13, 2016
1 parent 60ce83f commit 2ca4236
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"http-server": "0.8.0",
"istanbul": "0.3.22",
"jasmine": "2.4.1",
"jasmine-ajax": "^3.2.0",
"jasmine-core": "2.4.1",
"karma": "0.13.15",
"karma-browserify": "4.4.2",
Expand Down
5 changes: 5 additions & 0 deletions src/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ export class Observable<T> implements CoreOperators<T> {
return this.source.subscribe(subscriber);
}

static get: <T>(url: string | any) => Observable<any>;
static post: <T>(url: string | any, body?: any) => Observable<any>;
static ajax: <T>(options: string | any) => Observable<any>;
static getJSON: <T>(url: string | any) => Observable<any>;

// static method stubs
static ajax: AjaxCreationMethod;
static bindCallback: typeof BoundCallbackObservable.create;
Expand Down
5 changes: 5 additions & 0 deletions src/add/observable/dom/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Observable} from '../../../Observable';
import {get} from '../../../observable/dom/get';
Observable.get = get;

export var _void: void;
5 changes: 5 additions & 0 deletions src/add/observable/dom/getJSON.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Observable} from '../../../Observable';
import {getJSON} from '../../../observable/dom/getJSON';
Observable.getJSON = getJSON;

export var _void: void;
5 changes: 5 additions & 0 deletions src/add/observable/dom/post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Observable} from '../../../Observable';
import {post} from '../../../observable/dom/post';
Observable.post = post;

export var _void: void;
12 changes: 12 additions & 0 deletions src/observable/dom/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {Observable} from '../../Observable';
import {AjaxObservable} from './ajax';

function get(url: string | any): Observable<any> {
if (typeof url === 'string') {
return new AjaxObservable({ url });
} else {
return new AjaxObservable(url);
}
}

export { AjaxObservable, get };
12 changes: 12 additions & 0 deletions src/observable/dom/getJSON.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {root} from '../../util/root';
import {Observable} from '../../Observable';
import {AjaxObservable} from './ajax';

function getJSON(url: string | any): Observable<any> {
if (!root.JSON && typeof root.JSON.parse !== 'function') {
throw new TypeError('JSON is not supported in your runtime.');
}
return new AjaxObservable({ url, emitType: 'json', responseType: 'json' });
}

export { AjaxObservable, getJSON };
13 changes: 13 additions & 0 deletions src/observable/dom/post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Observable} from '../../Observable';
import {AjaxObservable} from './ajax';

function post(url: string | any, body?: any): Observable<any> {
if (typeof url === 'string') {
return new AjaxObservable({ url, body, method: 'POST' });
} else {
(<any> url).method = 'POST';
return new AjaxObservable((<any> url));
}
}

export { AjaxObservable, post };

0 comments on commit 2ca4236

Please sign in to comment.