// Compiled by ClojureScript 0.0-2138
goog.provide('lt.objs.context');
goog.require('cljs.core');
goog.require('lt.object');
goog.require('lt.object');
lt.objs.context.contexts = cljs.core.atom.call(null,cljs.core.PersistentHashSet.EMPTY);
lt.objs.context.groups = cljs.core.atom.call(null,cljs.core.PersistentArrayMap.EMPTY);
lt.objs.context.ctx__GT_obj = cljs.core.atom.call(null,cljs.core.PersistentArrayMap.EMPTY);
lt.objs.context.ctx__GT_group = cljs.core.atom.call(null,cljs.core.PersistentArrayMap.EMPTY);
lt.objs.context.group__GT_ctxs = cljs.core.atom.call(null,cljs.core.PersistentArrayMap.EMPTY);
lt.objs.context.append_group = (function append_group(group,name){return cljs.core.swap_BANG_.call(null,lt.objs.context.groups,(function (all){if(cljs.core.truth_(all.call(null,group)))
{return cljs.core.update_in.call(null,all,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [group], null),cljs.core.conj,name);
} else
{return cljs.core.assoc.call(null,all,group,cljs.core.PersistentHashSet.fromArray([name], true));
}
}));
});
lt.objs.context.in_QMARK_ = (function in_QMARK_(k){return cljs.core.deref.call(null,lt.objs.context.contexts).call(null,k);
});
lt.objs.context.out_BANG_ = (function() {
var out_BANG_ = null;
var out_BANG___1 = (function (ctxs){var ctxs__$1 = ((cljs.core.coll_QMARK_.call(null,ctxs))?ctxs:new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [ctxs], null));cljs.core.swap_BANG_.call(null,lt.objs.context.contexts,(function (p1__7799_SHARP_){return cljs.core.apply.call(null,cljs.core.disj,p1__7799_SHARP_,ctxs__$1);
}));
cljs.core.swap_BANG_.call(null,lt.objs.context.ctx__GT_obj,(function (p1__7800_SHARP_){return cljs.core.apply.call(null,cljs.core.dissoc,p1__7800_SHARP_,ctxs__$1);
}));
return lt.object.raise.call(null,lt.objs.context.ctx_obj,new cljs.core.Keyword(null,"log!","log!",1017231567));
});
var out_BANG___2 = (function (ctxs,_){return out_BANG_.call(null,ctxs);
});
out_BANG_ = function(ctxs,_){
switch(arguments.length){
case 1:
return out_BANG___1.call(this,ctxs);
case 2:
return out_BANG___2.call(this,ctxs,_);
}
throw(new Error('Invalid arity: ' + arguments.length));
};
out_BANG_.cljs$core$IFn$_invoke$arity$1 = out_BANG___1;
out_BANG_.cljs$core$IFn$_invoke$arity$2 = out_BANG___2;
return out_BANG_;
})()
;
/**
* @param {...*} var_args
*/
lt.objs.context.in_BANG_ = (function() { 
var in_BANG___delegate = function (ctxs,p__7803){var vec__7809 = p__7803;var obj = cljs.core.nth.call(null,vec__7809,0,null);var ctxs__$1 = ((cljs.core.coll_QMARK_.call(null,ctxs))?ctxs:new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [ctxs], null));cljs.core.swap_BANG_.call(null,lt.objs.context.contexts,(function (p1__7801_SHARP_){return cljs.core.apply.call(null,cljs.core.conj,p1__7801_SHARP_,ctxs__$1);
}));
cljs.core.swap_BANG_.call(null,lt.objs.context.ctx__GT_obj,(function (p1__7802_SHARP_){return cljs.core.merge.call(null,p1__7802_SHARP_,cljs.core.zipmap.call(null,ctxs__$1,cljs.core.repeat.call(null,obj)));
}));
lt.object.raise.call(null,lt.objs.context.ctx_obj,new cljs.core.Keyword(null,"log!","log!",1017231567));
var seq__7810 = cljs.core.seq.call(null,ctxs__$1);var chunk__7811 = null;var count__7812 = 0;var i__7813 = 0;while(true){
if((i__7813 < count__7812))
{var c = cljs.core._nth.call(null,chunk__7811,i__7813);var temp__4092__auto___7814 = cljs.core.deref.call(null,lt.objs.context.group__GT_ctxs).call(null,cljs.core.deref.call(null,lt.objs.context.ctx__GT_group).call(null,c));if(cljs.core.truth_(temp__4092__auto___7814))
{var group_7815 = temp__4092__auto___7814;lt.objs.context.out_BANG_.call(null,group_7815);
} else
{}
{
var G__7816 = seq__7810;
var G__7817 = chunk__7811;
var G__7818 = count__7812;
var G__7819 = (i__7813 + 1);
seq__7810 = G__7816;
chunk__7811 = G__7817;
count__7812 = G__7818;
i__7813 = G__7819;
continue;
}
} else
{var temp__4092__auto__ = cljs.core.seq.call(null,seq__7810);if(temp__4092__auto__)
{var seq__7810__$1 = temp__4092__auto__;if(cljs.core.chunked_seq_QMARK_.call(null,seq__7810__$1))
{var c__4262__auto__ = cljs.core.chunk_first.call(null,seq__7810__$1);{
var G__7820 = cljs.core.chunk_rest.call(null,seq__7810__$1);
var G__7821 = c__4262__auto__;
var G__7822 = cljs.core.count.call(null,c__4262__auto__);
var G__7823 = 0;
seq__7810 = G__7820;
chunk__7811 = G__7821;
count__7812 = G__7822;
i__7813 = G__7823;
continue;
}
} else
{var c = cljs.core.first.call(null,seq__7810__$1);var temp__4092__auto___7824__$1 = cljs.core.deref.call(null,lt.objs.context.group__GT_ctxs).call(null,cljs.core.deref.call(null,lt.objs.context.ctx__GT_group).call(null,c));if(cljs.core.truth_(temp__4092__auto___7824__$1))
{var group_7825 = temp__4092__auto___7824__$1;lt.objs.context.out_BANG_.call(null,group_7825);
} else
{}
{
var G__7826 = cljs.core.next.call(null,seq__7810__$1);
var G__7827 = null;
var G__7828 = 0;
var G__7829 = 0;
seq__7810 = G__7826;
chunk__7811 = G__7827;
count__7812 = G__7828;
i__7813 = G__7829;
continue;
}
}
} else
{return null;
}
}
break;
}
};
var in_BANG_ = function (ctxs,var_args){
var p__7803 = null;if (arguments.length > 1) {
  p__7803 = cljs.core.array_seq(Array.prototype.slice.call(arguments, 1),0);} 
return in_BANG___delegate.call(this,ctxs,p__7803);};
in_BANG_.cljs$lang$maxFixedArity = 1;
in_BANG_.cljs$lang$applyTo = (function (arglist__7830){
var ctxs = cljs.core.first(arglist__7830);
var p__7803 = cljs.core.rest(arglist__7830);
return in_BANG___delegate(ctxs,p__7803);
});
in_BANG_.cljs$core$IFn$_invoke$arity$variadic = in_BANG___delegate;
return in_BANG_;
})()
;
/**
* @param {...*} var_args
*/
lt.objs.context.toggle_BANG_ = (function() { 
var toggle_BANG___delegate = function (ctxs,p__7831){var vec__7837 = p__7831;var obj = cljs.core.nth.call(null,vec__7837,0,null);var seq__7838 = cljs.core.seq.call(null,ctxs);var chunk__7839 = null;var count__7840 = 0;var i__7841 = 0;while(true){
if((i__7841 < count__7840))
{var c = cljs.core._nth.call(null,chunk__7839,i__7841);if(cljs.core.truth_(lt.objs.context.in_QMARK_.call(null,c)))
{lt.objs.context.out_BANG_.call(null,c);
} else
{lt.objs.context.in_BANG_.call(null,c,obj);
}
{
var G__7842 = seq__7838;
var G__7843 = chunk__7839;
var G__7844 = count__7840;
var G__7845 = (i__7841 + 1);
seq__7838 = G__7842;
chunk__7839 = G__7843;
count__7840 = G__7844;
i__7841 = G__7845;
continue;
}
} else
{var temp__4092__auto__ = cljs.core.seq.call(null,seq__7838);if(temp__4092__auto__)
{var seq__7838__$1 = temp__4092__auto__;if(cljs.core.chunked_seq_QMARK_.call(null,seq__7838__$1))
{var c__4262__auto__ = cljs.core.chunk_first.call(null,seq__7838__$1);{
var G__7846 = cljs.core.chunk_rest.call(null,seq__7838__$1);
var G__7847 = c__4262__auto__;
var G__7848 = cljs.core.count.call(null,c__4262__auto__);
var G__7849 = 0;
seq__7838 = G__7846;
chunk__7839 = G__7847;
count__7840 = G__7848;
i__7841 = G__7849;
continue;
}
} else
{var c = cljs.core.first.call(null,seq__7838__$1);if(cljs.core.truth_(lt.objs.context.in_QMARK_.call(null,c)))
{lt.objs.context.out_BANG_.call(null,c);
} else
{lt.objs.context.in_BANG_.call(null,c,obj);
}
{
var G__7850 = cljs.core.next.call(null,seq__7838__$1);
var G__7851 = null;
var G__7852 = 0;
var G__7853 = 0;
seq__7838 = G__7850;
chunk__7839 = G__7851;
count__7840 = G__7852;
i__7841 = G__7853;
continue;
}
}
} else
{return null;
}
}
break;
}
};
var toggle_BANG_ = function (ctxs,var_args){
var p__7831 = null;if (arguments.length > 1) {
  p__7831 = cljs.core.array_seq(Array.prototype.slice.call(arguments, 1),0);} 
return toggle_BANG___delegate.call(this,ctxs,p__7831);};
toggle_BANG_.cljs$lang$maxFixedArity = 1;
toggle_BANG_.cljs$lang$applyTo = (function (arglist__7854){
var ctxs = cljs.core.first(arglist__7854);
var p__7831 = cljs.core.rest(arglist__7854);
return toggle_BANG___delegate(ctxs,p__7831);
});
toggle_BANG_.cljs$core$IFn$_invoke$arity$variadic = toggle_BANG___delegate;
return toggle_BANG_;
})()
;
lt.objs.context.current = (function current(){return cljs.core.deref.call(null,lt.objs.context.contexts);
});
lt.objs.context.group_BANG_ = (function group_BANG_(ctx,group){cljs.core.swap_BANG_.call(null,lt.objs.context.ctx__GT_group,cljs.core.assoc,ctx,group);
return cljs.core.swap_BANG_.call(null,lt.objs.context.group__GT_ctxs,cljs.core.update_in,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [group], null),cljs.core.conj,ctx);
});
lt.objs.context.__GT_obj = (function __GT_obj(ctx){return cljs.core.deref.call(null,lt.objs.context.ctx__GT_obj).call(null,ctx);
});
lt.objs.context.enqueue = (function enqueue(coll,buffer,size){if(cljs.core._EQ_.call(null,size,cljs.core.count.call(null,buffer)))
{return cljs.core.conj.call(null,cljs.core.pop.call(null,buffer),coll);
} else
{return cljs.core.conj.call(null,buffer,coll);
}
});
lt.objs.context.__BEH__log = (function __BEH__log(this$){var size = new cljs.core.Keyword(null,"buffer-size","buffer-size",4237691104).cljs$core$IFn$_invoke$arity$1(cljs.core.deref.call(null,this$));var ctx = cljs.core.deref.call(null,lt.objs.context.contexts);return lt.object.update_BANG_.call(null,this$,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"history","history",1940838406)], null),(function (p1__7855_SHARP_){return lt.objs.context.enqueue.call(null,ctx,p1__7855_SHARP_,size);
}));
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.context","log","lt.objs.context/log",4046231399),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.context.__BEH__log,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"log!","log!",1017231567),null], null), null),new cljs.core.Keyword(null,"debounce","debounce",1556599227),16);
lt.object.object_STAR_.call(null,new cljs.core.Keyword("lt.objs.context","context","lt.objs.context/context",4461036756),new cljs.core.Keyword(null,"tags","tags",1017456523),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"context","context",1965435169),null], null), null),new cljs.core.Keyword(null,"history","history",1940838406),cljs.core.PersistentQueue.EMPTY,new cljs.core.Keyword(null,"buffer-size","buffer-size",4237691104),8,new cljs.core.Keyword(null,"init","init",1017141378),(function (this$){return null;
}));
lt.objs.context.ctx_obj = lt.object.create.call(null,new cljs.core.Keyword("lt.objs.context","context","lt.objs.context/context",4461036756));
