Update rx ajax typings

pull/7430/head
Berkeley Martinez 2016-05-17 10:25:20 -07:00
parent 2573dc0b22
commit 1db5caa701
1 changed files with 16 additions and 29 deletions

View File

@ -86,7 +86,6 @@ function normalizeAjaxErrorEvent(e, xhr, type) {
}
/*
*
* Creates an observable for an Ajax request with either a settings object
* with url, headers, etc or a string for a URL.
*
@ -94,20 +93,17 @@ function normalizeAjaxErrorEvent(e, xhr, type) {
* source = Rx.DOM.ajax('/products');
* source = Rx.DOM.ajax( url: 'products', method: 'GET' });
*
* @param {Object} settings Can be one of the following:
* interface Options {
* url: String, // URL of the request
* body?: Object, // The body of the request
* method? = 'GET' : 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE',
* async? = true: Boolean, // Whether the request is async
* headers?: Object, // optional headers
* crossDomain?: true // if a cross domain request, else false
* }
*
* A string of the URL to make the Ajax call.
* An object with the following properties
* - url: URL of the request
* - body: The body of the request
* - method: Method of the request, such as GET, POST, PUT, PATCH, DELETE
* - async: Whether the request is async
* - headers: Optional headers
* - crossDomain: true if a cross domain request, else false
*
* @returns {Observable} An observable sequence containing the XMLHttpRequest.
*/
* ajax$(url?: String, options: Options) => Observable[XMLHttpRequest]
*/
export function ajax$(options) {
var settings = {
method: 'GET',
@ -242,14 +238,8 @@ export function ajax$(options) {
});
}
/**
* Creates an observable sequence from an Ajax POST Request with the body.
*
* @param {String} url The URL to POST
* @param {Object} body The body to POST
* @returns {Observable} The observable sequence which contains the response
* from the Ajax POST.
*/
// Creates an observable sequence from an Ajax POST Request with the body.
// post$(url: String, body: Object) => Observable[Any]
export function post$(url, body) {
try {
body = JSON.stringify(body);
@ -260,6 +250,7 @@ export function post$(url, body) {
return ajax$({ url, body, method: 'POST' });
}
// postJSON$(url: String, body: Object) => Observable[Object]
export function postJSON$(url, body) {
try {
body = JSON.stringify(body);
@ -280,13 +271,8 @@ export function postJSON$(url, body) {
.map(({ response }) => response);
}
/**
* Creates an observable sequence from an Ajax GET Request with the body.
*
* @param {String} url The URL to GET
* @returns {Observable} The observable sequence which
* contains the response from the Ajax GET.
*/
// Creates an observable sequence from an Ajax GET Request with the body.
// get$(url: String) => Obserable[Any]
export function get$(url) {
return ajax$({ url: url });
}
@ -297,6 +283,7 @@ export function get$(url) {
* @param {String} url The URL to GET
* @returns {Observable} The observable sequence which contains the parsed JSON
*/
// getJSON$(url: String) => Observable[Object];
export function getJSON$(url) {
return ajax$({
url: url,