// Compiled by ClojureScript 0.0-2138
goog.provide('lt.objs.clients.local');
goog.require('cljs.core');
goog.require('lt.util.dom');
goog.require('lt.util.js');
goog.require('lt.objs.files');
goog.require('lt.util.js');
goog.require('lt.util.dom');
goog.require('cljs.reader');
goog.require('crate.core');
goog.require('clojure.string');
goog.require('lt.objs.files');
goog.require('lt.objs.sidebar.clients');
goog.require('lt.objs.eval');
goog.require('lt.objs.clients');
goog.require('clojure.string');
goog.require('lt.object');
goog.require('cljs.reader');
goog.require('lt.object');
goog.require('lt.objs.console');
goog.require('lt.objs.console');
goog.require('crate.core');
goog.require('lt.objs.eval');
goog.require('lt.objs.clients');
goog.require('lt.objs.sidebar.clients');
lt.objs.clients.local.client_name = "LightTable-UI";
lt.objs.clients.local.on_message = (function (){var method_table__4372__auto__ = cljs.core.atom.call(null,cljs.core.PersistentArrayMap.EMPTY);var prefer_table__4373__auto__ = cljs.core.atom.call(null,cljs.core.PersistentArrayMap.EMPTY);var method_cache__4374__auto__ = cljs.core.atom.call(null,cljs.core.PersistentArrayMap.EMPTY);var cached_hierarchy__4375__auto__ = cljs.core.atom.call(null,cljs.core.PersistentArrayMap.EMPTY);var hierarchy__4376__auto__ = cljs.core.get.call(null,cljs.core.PersistentArrayMap.EMPTY,new cljs.core.Keyword(null,"hierarchy","hierarchy",3129050535),cljs.core.get_global_hierarchy.call(null));return (new cljs.core.MultiFn("on-message",cljs.core.identity,new cljs.core.Keyword(null,"default","default",2558708147),hierarchy__4376__auto__,method_table__4372__auto__,prefer_table__4373__auto__,method_cache__4374__auto__,cached_hierarchy__4375__auto__));
})();
cljs.core._add_method.call(null,lt.objs.clients.local.on_message,new cljs.core.Keyword(null,"editor.eval.cljs.exec","editor.eval.cljs.exec",866638030),(function (_,data,cb){var seq__7511 = cljs.core.seq.call(null,new cljs.core.Keyword(null,"results","results",2111450984).cljs$core$IFn$_invoke$arity$1(data));var chunk__7512 = null;var count__7513 = 0;var i__7514 = 0;while(true){
if((i__7514 < count__7513))
{var res = cljs.core._nth.call(null,chunk__7512,i__7514);var code_7517 = new cljs.core.Keyword(null,"code","code",1016963423).cljs$core$IFn$_invoke$arity$1(res);try{lt.object.raise.call(null,lt.objs.clients.clients,new cljs.core.Keyword(null,"message","message",1968829305),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cb,new cljs.core.Keyword(null,"editor.eval.cljs.result","editor.eval.cljs.result",1580065178),new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"result","result",4374444943),lt.objs.eval.cljs_result_format.call(null,eval.call(window,code_7517)),new cljs.core.Keyword(null,"meta","meta",1017252215),cljs.core.merge.call(null,new cljs.core.Keyword(null,"meta","meta",1017252215).cljs$core$IFn$_invoke$arity$1(data),new cljs.core.Keyword(null,"meta","meta",1017252215).cljs$core$IFn$_invoke$arity$1(res))], null)], null));
}catch (e7515){var e_7518 = e7515;lt.object.raise.call(null,lt.objs.clients.clients,new cljs.core.Keyword(null,"message","message",1968829305),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cb,new cljs.core.Keyword(null,"editor.eval.cljs.exception","editor.eval.cljs.exception",4479049174),new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"ex","ex",1013907493),e_7518,new cljs.core.Keyword(null,"meta","meta",1017252215),new cljs.core.Keyword(null,"meta","meta",1017252215).cljs$core$IFn$_invoke$arity$1(res)], null)], null));
}{
var G__7519 = seq__7511;
var G__7520 = chunk__7512;
var G__7521 = count__7513;
var G__7522 = (i__7514 + 1);
seq__7511 = G__7519;
chunk__7512 = G__7520;
count__7513 = G__7521;
i__7514 = G__7522;
continue;
}
} else
{var temp__4092__auto__ = cljs.core.seq.call(null,seq__7511);if(temp__4092__auto__)
{var seq__7511__$1 = temp__4092__auto__;if(cljs.core.chunked_seq_QMARK_.call(null,seq__7511__$1))
{var c__4262__auto__ = cljs.core.chunk_first.call(null,seq__7511__$1);{
var G__7523 = cljs.core.chunk_rest.call(null,seq__7511__$1);
var G__7524 = c__4262__auto__;
var G__7525 = cljs.core.count.call(null,c__4262__auto__);
var G__7526 = 0;
seq__7511 = G__7523;
chunk__7512 = G__7524;
count__7513 = G__7525;
i__7514 = G__7526;
continue;
}
} else
{var res = cljs.core.first.call(null,seq__7511__$1);var code_7527 = new cljs.core.Keyword(null,"code","code",1016963423).cljs$core$IFn$_invoke$arity$1(res);try{lt.object.raise.call(null,lt.objs.clients.clients,new cljs.core.Keyword(null,"message","message",1968829305),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cb,new cljs.core.Keyword(null,"editor.eval.cljs.result","editor.eval.cljs.result",1580065178),new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"result","result",4374444943),lt.objs.eval.cljs_result_format.call(null,eval.call(window,code_7527)),new cljs.core.Keyword(null,"meta","meta",1017252215),cljs.core.merge.call(null,new cljs.core.Keyword(null,"meta","meta",1017252215).cljs$core$IFn$_invoke$arity$1(data),new cljs.core.Keyword(null,"meta","meta",1017252215).cljs$core$IFn$_invoke$arity$1(res))], null)], null));
}catch (e7516){var e_7528 = e7516;lt.object.raise.call(null,lt.objs.clients.clients,new cljs.core.Keyword(null,"message","message",1968829305),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cb,new cljs.core.Keyword(null,"editor.eval.cljs.exception","editor.eval.cljs.exception",4479049174),new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"ex","ex",1013907493),e_7528,new cljs.core.Keyword(null,"meta","meta",1017252215),new cljs.core.Keyword(null,"meta","meta",1017252215).cljs$core$IFn$_invoke$arity$1(res)], null)], null));
}{
var G__7529 = cljs.core.next.call(null,seq__7511__$1);
var G__7530 = null;
var G__7531 = 0;
var G__7532 = 0;
seq__7511 = G__7529;
chunk__7512 = G__7530;
count__7513 = G__7531;
i__7514 = G__7532;
continue;
}
}
} else
{return null;
}
}
break;
}
}));
cljs.core._add_method.call(null,lt.objs.clients.local.on_message,new cljs.core.Keyword(null,"editor.eval.js","editor.eval.js",1847417804),(function (_,data,cb){var code = lt.objs.eval.append_source_file.call(null,new cljs.core.Keyword(null,"code","code",1016963423).cljs$core$IFn$_invoke$arity$1(data),new cljs.core.Keyword(null,"path","path",1017337751).cljs$core$IFn$_invoke$arity$1(data));try{return lt.object.raise.call(null,lt.objs.clients.clients,new cljs.core.Keyword(null,"message","message",1968829305),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cb,new cljs.core.Keyword(null,"editor.eval.js.result","editor.eval.js.result",3021062051),new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"result","result",4374444943),eval.call(window,code),new cljs.core.Keyword(null,"meta","meta",1017252215),new cljs.core.Keyword(null,"meta","meta",1017252215).cljs$core$IFn$_invoke$arity$1(data)], null)], null));
}catch (e7533){var e = e7533;return lt.object.raise.call(null,lt.objs.clients.clients,new cljs.core.Keyword(null,"message","message",1968829305),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cb,new cljs.core.Keyword(null,"editor.eval.js.exception","editor.eval.js.exception",723801901),new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"ex","ex",1013907493),e,new cljs.core.Keyword(null,"meta","meta",1017252215),new cljs.core.Keyword(null,"meta","meta",1017252215).cljs$core$IFn$_invoke$arity$1(data)], null)], null));
}}));
cljs.core._add_method.call(null,lt.objs.clients.local.on_message,new cljs.core.Keyword(null,"editor.eval.css","editor.eval.css",1083014276),(function (_,data,cb){var name = [cljs.core.str("local-"),cljs.core.str(clojure.string.replace.call(null,new cljs.core.Keyword(null,"name","name",1017277949).cljs$core$IFn$_invoke$arity$1(data),/[^a-zA-Z0-9]+/,"-"))].join('');var cur = lt.util.dom.$.call(null,[cljs.core.str("#"),cljs.core.str(name)].join(''));if(cljs.core.truth_(cur))
{lt.util.dom.remove.call(null,cur);
} else
{}
return lt.util.dom.append.call(null,lt.util.dom.$.call(null,new cljs.core.Keyword(null,"head","head",1017102674)),crate.core.html.call(null,new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"style","style",1123684643),new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"type","type",1017479852),"text/css",new cljs.core.Keyword(null,"id","id",1013907597),name], null),new cljs.core.Keyword(null,"code","code",1016963423).cljs$core$IFn$_invoke$arity$1(data)], null)));
}));
cljs.core._add_method.call(null,lt.objs.clients.local.on_message,new cljs.core.Keyword(null,"client.close","client.close",2801102215),(function (_,___$1,___$2){return lt.objs.clients.rem_BANG_.call(null,lt.objs.clients.by_name.call(null,lt.objs.clients.local.client_name));
}));
cljs.core._add_method.call(null,lt.objs.clients.local.on_message,new cljs.core.Keyword(null,"default","default",2558708147),(function (){return null;
}));
lt.objs.clients.local.__BEH__send_BANG_ = (function __BEH__send_BANG_(this$,data){return lt.objs.clients.local.on_message.call(null,cljs.core.keyword.call(null,new cljs.core.Keyword(null,"command","command",1964298941).cljs$core$IFn$_invoke$arity$1(data)),new cljs.core.Keyword(null,"data","data",1016980252).cljs$core$IFn$_invoke$arity$1(data),new cljs.core.Keyword(null,"cb","cb",1013907409).cljs$core$IFn$_invoke$arity$1(data));
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.clients.local","send!","lt.objs.clients.local/send!",3140293818),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.clients.local.__BEH__send_BANG_,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"send!","send!",1123226891),null], null), null));
lt.objs.clients.local.init = (function init(){return lt.objs.clients.handle_connection_BANG_.call(null,new cljs.core.PersistentArrayMap(null, 5, [new cljs.core.Keyword(null,"name","name",1017277949),lt.objs.clients.local.client_name,new cljs.core.Keyword(null,"tags","tags",1017456523),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"client.local","client.local",2809491194)], null),new cljs.core.Keyword(null,"root-relative","root-relative",4164603593),lt.objs.files.lt_home.call(null,"core"),new cljs.core.Keyword(null,"commands","commands",4706336250),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 3, [new cljs.core.Keyword(null,"editor.eval.cljs.exec","editor.eval.cljs.exec",866638030),null,new cljs.core.Keyword(null,"editor.eval.css","editor.eval.css",1083014276),null,new cljs.core.Keyword(null,"editor.eval.js","editor.eval.js",1847417804),null], null), null),new cljs.core.Keyword(null,"type","type",1017479852),"LT-UI"], null));
});
lt.objs.sidebar.clients.add_connector.call(null,new cljs.core.PersistentArrayMap(null, 3, [new cljs.core.Keyword(null,"name","name",1017277949),"Light Table UI",new cljs.core.Keyword(null,"desc","desc",1016984067),"Connect to this instance of Light Table and evaluate in the local context.",new cljs.core.Keyword(null,"connect","connect",1965255772),(function (){if(cljs.core.truth_(lt.objs.clients.by_name.call(null,lt.objs.clients.local.client_name)))
{return null;
} else
{return lt.objs.clients.local.init.call(null);
}
})], null));
