// 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__14647 = cljs.core.seq.call(null,new cljs.core.Keyword(null,"results","results",2111450984).cljs$core$IFn$_invoke$arity$1(data));var chunk__14648 = null;var count__14649 = 0;var i__14650 = 0;while(true){
if((i__14650 < count__14649))
{var res = cljs.core._nth.call(null,chunk__14648,i__14650);var code_14653 = 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_14653)),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 (e14651){var e_14654 = e14651;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_14654,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__14655 = seq__14647;
var G__14656 = chunk__14648;
var G__14657 = count__14649;
var G__14658 = (i__14650 + 1);
seq__14647 = G__14655;
chunk__14648 = G__14656;
count__14649 = G__14657;
i__14650 = G__14658;
continue;
}
} else
{var temp__4092__auto__ = cljs.core.seq.call(null,seq__14647);if(temp__4092__auto__)
{var seq__14647__$1 = temp__4092__auto__;if(cljs.core.chunked_seq_QMARK_.call(null,seq__14647__$1))
{var c__4262__auto__ = cljs.core.chunk_first.call(null,seq__14647__$1);{
var G__14659 = cljs.core.chunk_rest.call(null,seq__14647__$1);
var G__14660 = c__4262__auto__;
var G__14661 = cljs.core.count.call(null,c__4262__auto__);
var G__14662 = 0;
seq__14647 = G__14659;
chunk__14648 = G__14660;
count__14649 = G__14661;
i__14650 = G__14662;
continue;
}
} else
{var res = cljs.core.first.call(null,seq__14647__$1);var code_14663 = 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_14663)),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 (e14652){var e_14664 = e14652;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_14664,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__14665 = cljs.core.next.call(null,seq__14647__$1);
var G__14666 = null;
var G__14667 = 0;
var G__14668 = 0;
seq__14647 = G__14665;
chunk__14648 = G__14666;
count__14649 = G__14667;
i__14650 = G__14668;
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 (e14669){var e = e14669;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));
