Update rx ajax typings
This commit is contained in:
@ -86,7 +86,6 @@ function normalizeAjaxErrorEvent(e, xhr, type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
|
||||||
* Creates an observable for an Ajax request with either a settings object
|
* Creates an observable for an Ajax request with either a settings object
|
||||||
* with url, headers, etc or a string for a URL.
|
* 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('/products');
|
||||||
* source = Rx.DOM.ajax( url: 'products', method: 'GET' });
|
* 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.
|
* ajax$(url?: String, options: Options) => Observable[XMLHttpRequest]
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export function ajax$(options) {
|
export function ajax$(options) {
|
||||||
var settings = {
|
var settings = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -242,14 +238,8 @@ export function ajax$(options) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Creates an observable sequence from an Ajax POST Request with the body.
|
||||||
* Creates an observable sequence from an Ajax POST Request with the body.
|
// post$(url: String, body: Object) => Observable[Any]
|
||||||
*
|
|
||||||
* @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.
|
|
||||||
*/
|
|
||||||
export function post$(url, body) {
|
export function post$(url, body) {
|
||||||
try {
|
try {
|
||||||
body = JSON.stringify(body);
|
body = JSON.stringify(body);
|
||||||
@ -260,6 +250,7 @@ export function post$(url, body) {
|
|||||||
return ajax$({ url, body, method: 'POST' });
|
return ajax$({ url, body, method: 'POST' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// postJSON$(url: String, body: Object) => Observable[Object]
|
||||||
export function postJSON$(url, body) {
|
export function postJSON$(url, body) {
|
||||||
try {
|
try {
|
||||||
body = JSON.stringify(body);
|
body = JSON.stringify(body);
|
||||||
@ -280,13 +271,8 @@ export function postJSON$(url, body) {
|
|||||||
.map(({ response }) => response);
|
.map(({ response }) => response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Creates an observable sequence from an Ajax GET Request with the body.
|
||||||
* Creates an observable sequence from an Ajax GET Request with the body.
|
// get$(url: String) => Obserable[Any]
|
||||||
*
|
|
||||||
* @param {String} url The URL to GET
|
|
||||||
* @returns {Observable} The observable sequence which
|
|
||||||
* contains the response from the Ajax GET.
|
|
||||||
*/
|
|
||||||
export function get$(url) {
|
export function get$(url) {
|
||||||
return ajax$({ url: url });
|
return ajax$({ url: url });
|
||||||
}
|
}
|
||||||
@ -297,6 +283,7 @@ export function get$(url) {
|
|||||||
* @param {String} url The URL to GET
|
* @param {String} url The URL to GET
|
||||||
* @returns {Observable} The observable sequence which contains the parsed JSON
|
* @returns {Observable} The observable sequence which contains the parsed JSON
|
||||||
*/
|
*/
|
||||||
|
// getJSON$(url: String) => Observable[Object];
|
||||||
export function getJSON$(url) {
|
export function getJSON$(url) {
|
||||||
return ajax$({
|
return ajax$({
|
||||||
url: url,
|
url: url,
|
||||||
|
Reference in New Issue
Block a user