// Compiled by ClojureScript 0.0-2138
goog.provide('fetch.core');
goog.require('cljs.core');
goog.require('goog.Uri.QueryData');
goog.require('goog.events');
goog.require('cljs.reader');
goog.require('clojure.string');
goog.require('goog.structs');
goog.require('goog.Uri.QueryData');
goog.require('clojure.string');
goog.require('goog.structs');
goog.require('cljs.reader');
goog.require('goog.net.XhrIo');
goog.require('goog.net.XhrIo');
goog.require('goog.events');
fetch.core.__GT_method = (function __GT_method(m){return clojure.string.upper_case.call(null,cljs.core.name.call(null,m));
});
fetch.core.parse_route = (function parse_route(route){if(typeof route === 'string')
{return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, ["GET",route], null);
} else
{if(cljs.core.vector_QMARK_.call(null,route))
{var vec__16041 = route;var m = cljs.core.nth.call(null,vec__16041,0,null);var u = cljs.core.nth.call(null,vec__16041,1,null);return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [fetch.core.__GT_method.call(null,m),u], null);
} else
{if(new cljs.core.Keyword(null,"else","else",1017020587))
{return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, ["GET",route], null);
} else
{return null;
}
}
}
});
fetch.core.__GT_data = (function __GT_data(d){var cur = cljs.core.clj__GT_js.call(null,d);var query = goog.Uri.QueryData.createFromMap((new goog.structs.Map(cur)));return [cljs.core.str(query)].join('');
});
fetch.core.__GT_callback = (function __GT_callback(callback){if(cljs.core.truth_(callback))
{return (function (req){var data = req.getResponseText();return callback.call(null,data);
});
} else
{return null;
}
});
/**
* @param {...*} var_args
*/
fetch.core.xhr = (function() { 
var xhr__delegate = function (route,content,callback,p__16042){var vec__16045 = p__16042;var opts = cljs.core.nth.call(null,vec__16045,0,null);var req = (new goog.net.XhrIo());var vec__16046 = fetch.core.parse_route.call(null,route);var method = cljs.core.nth.call(null,vec__16046,0,null);var uri = cljs.core.nth.call(null,vec__16046,1,null);var data = fetch.core.__GT_data.call(null,content);var callback__$1 = fetch.core.__GT_callback.call(null,callback);if(cljs.core.truth_(callback__$1))
{goog.events.listen(req,goog.net.EventType.COMPLETE,(function (){return callback__$1.call(null,req);
}));
} else
{}
return req.send(uri,method,data,(cljs.core.truth_(opts)?cljs.core.clj__GT_js.call(null,opts):null));
};
var xhr = function (route,content,callback,var_args){
var p__16042 = null;if (arguments.length > 3) {
  p__16042 = cljs.core.array_seq(Array.prototype.slice.call(arguments, 3),0);} 
return xhr__delegate.call(this,route,content,callback,p__16042);};
xhr.cljs$lang$maxFixedArity = 3;
xhr.cljs$lang$applyTo = (function (arglist__16047){
var route = cljs.core.first(arglist__16047);
arglist__16047 = cljs.core.next(arglist__16047);
var content = cljs.core.first(arglist__16047);
arglist__16047 = cljs.core.next(arglist__16047);
var callback = cljs.core.first(arglist__16047);
var p__16042 = cljs.core.rest(arglist__16047);
return xhr__delegate(route,content,callback,p__16042);
});
xhr.cljs$core$IFn$_invoke$arity$variadic = xhr__delegate;
return xhr;
})()
;
