From 1db5caa7017312d1b2da4871e434dbfef374c994 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Tue, 17 May 2016 10:25:20 -0700 Subject: [PATCH] Update rx ajax typings --- common/utils/ajax-stream.js | 45 +++++++++++++------------------------ 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/common/utils/ajax-stream.js b/common/utils/ajax-stream.js index 9ad5034b11e..b5588c29a9f 100644 --- a/common/utils/ajax-stream.js +++ b/common/utils/ajax-stream.js @@ -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,