@@ -182,57 +182,62 @@ var Signal = function() {
184 var HTTP = function() {
184 var HTTP = function() {
185− var fetch = function(how) { return function(url) {
185+
186− var thread = Elm.Input(["Waiting"]);
188− if (window.XMLHttpRequest) { request = new XMLHttpRequest(); }
189− else if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHTTP"); }
190− request.onreadystatechange = function(e) {
191− if (request.readyState === 4) {
192− Dispatcher.notify(thread.id,
193− request.status === 200
194− ? ["Success", toElmString(request.responseText)]
195− : ["Failure", request.status, toElmString(request.statusText)]);
198− request.open(how, Value.toText(url), true);
203− var fetches = function(how) { return function(input) {
186+ function request(verb) { return function(url) { return function(data) {
204− var output = Elm.Input(["Nothing"]);
187+ return function(headers) {
205− var fetcher = Elm.Lift(update, [input]);
188+ return {0 : "Request",
206− var combine = Elm.Lift(function(x) { return function(y) { return x; } }, [output,fetcher]);
189+ length : 1,
207− function update(strOpt) {
190+ verb : Foreign.JavaScript.castStringToJSString(verb),
208− if (strOpt[0] !== "Just") {
191+ url : Foreign.JavaScript.castStringToJSString(url),
209− try { Dispatcher.notify(output.id, ["Nothing"]); } catch(e) {}
192+ data : data === null ? null : Foreign.JavaScript.castStringToJSString(data),
210− return [];
193+ headers : headers }; }; }; };
213− Dispatcher.notify(output.id, ["Just", ["Waiting"]]);
214− } catch(e) { output.value = ["Just", ["Waiting"]]; }
216− if (window.XMLHttpRequest) { request = new XMLHttpRequest(); }
217− else if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHTTP"); }
218− request.onreadystatechange = function(e) {
219− if (request.readyState === 4) {
220− Dispatcher.notify(output.id,
221− ["Just", request.status === 200
222− ? ["Success", toElmString(request.responseText)]
223− : ["Failure", request.status, toElmString(request.statusText)]]);
226− request.open(how, Value.toText(strOpt[1]), true);
227− request.send(null);
195+ function get(url) { return request("GET")(url)(null)(["Nil"]); }
228− return [];
196+ function post(url) { return function(data) {
229− }
197+ return request("POST")(url)(data)(["Nil"]); }; }
231− };
199+ function sendReq(responses) { return function(req) {
200+ Dispatcher.notify(responses.id,["Waiting"]);
202+ if (window.XMLHttpRequest) {
203+ request = new XMLHttpRequest();
204+ } else if (window.ActiveXObject) {
205+ request = new ActiveXObject("Microsoft.XMLHTTP");
207+ request.onreadystatechange = function(e) {
208+ if (request.readyState === 4) {
211+ request.status === 200
212+ ? ["Success", toElmString(request.responseText)]
213+ : ["Failure", request.status, toElmString(request.statusText)]);
233− return {get : fetch("GET"), post : fetch("POST"),
216+ request.open(req.verb, req.url, true);
234− gets : fetches("GET"), posts : fetches("POST")
217+ List.map(function(pair) {
218+ request.setRequestHeader(
219+ Foreign.JavaScript.castStringToJSString(pair[1]),
220+ Foreign.JavaScript.castStringToJSString(pair[2]));
222+ request.send(req.data);
227+ function send(requests) {
228+ var responses = Elm.Input(["Waiting"]);
229+ var sender = Elm.Lift(sendReq(responses), [requests]);
230+ var combine = Elm.Lift(function(x){return function(y){return x;}},
231+ [responses,sender]);
239+ sendGet : function(urls){return send(Elm.Lift(get,[urls]));}
237 var Random = function() {
242 var Random = function() {
238 var inRange = function(min) { return function(max) {
243 var inRange = function(min) { return function(max) {