// 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__12826_SHARP_){return cljs.core.apply.call(null,cljs.core.disj,p1__12826_SHARP_,ctxs__$1);
}));
cljs.core.swap_BANG_.call(null,lt.objs.context.ctx__GT_obj,(function (p1__12827_SHARP_){return cljs.core.apply.call(null,cljs.core.dissoc,p1__12827_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__12830){var vec__12836 = p__12830;var obj = cljs.core.nth.call(null,vec__12836,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__12828_SHARP_){return cljs.core.apply.call(null,cljs.core.conj,p1__12828_SHARP_,ctxs__$1);
}));
cljs.core.swap_BANG_.call(null,lt.objs.context.ctx__GT_obj,(function (p1__12829_SHARP_){return cljs.core.merge.call(null,p1__12829_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__12837 = cljs.core.seq.call(null,ctxs__$1);var chunk__12838 = null;var count__12839 = 0;var i__12840 = 0;while(true){
if((i__12840 < count__12839))
{var c = cljs.core._nth.call(null,chunk__12838,i__12840);var temp__4092__auto___12841 = 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___12841))
{var group_12842 = temp__4092__auto___12841;lt.objs.context.out_BANG_.call(null,group_12842);
} else
{}
{
var G__12843 = seq__12837;
var G__12844 = chunk__12838;
var G__12845 = count__12839;
var G__12846 = (i__12840 + 1);
seq__12837 = G__12843;
chunk__12838 = G__12844;
count__12839 = G__12845;
i__12840 = G__12846;
continue;
}
} else
{var temp__4092__auto__ = cljs.core.seq.call(null,seq__12837);if(temp__4092__auto__)
{var seq__12837__$1 = temp__4092__auto__;if(cljs.core.chunked_seq_QMARK_.call(null,seq__12837__$1))
{var c__4262__auto__ = cljs.core.chunk_first.call(null,seq__12837__$1);{
var G__12847 = cljs.core.chunk_rest.call(null,seq__12837__$1);
var G__12848 = c__4262__auto__;
var G__12849 = cljs.core.count.call(null,c__4262__auto__);
var G__12850 = 0;
seq__12837 = G__12847;
chunk__12838 = G__12848;
count__12839 = G__12849;
i__12840 = G__12850;
continue;
}
} else
{var c = cljs.core.first.call(null,seq__12837__$1);var temp__4092__auto___12851__$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___12851__$1))
{var group_12852 = temp__4092__auto___12851__$1;lt.objs.context.out_BANG_.call(null,group_12852);
} else
{}
{
var G__12853 = cljs.core.next.call(null,seq__12837__$1);
var G__12854 = null;
var G__12855 = 0;
var G__12856 = 0;
seq__12837 = G__12853;
chunk__12838 = G__12854;
count__12839 = G__12855;
i__12840 = G__12856;
continue;
}
}
} else
{return null;
}
}
break;
}
};
var in_BANG_ = function (ctxs,var_args){
var p__12830 = null;if (arguments.length > 1) {
  p__12830 = cljs.core.array_seq(Array.prototype.slice.call(arguments, 1),0);} 
return in_BANG___delegate.call(this,ctxs,p__12830);};
in_BANG_.cljs$lang$maxFixedArity = 1;
in_BANG_.cljs$lang$applyTo = (function (arglist__12857){
var ctxs = cljs.core.first(arglist__12857);
var p__12830 = cljs.core.rest(arglist__12857);
return in_BANG___delegate(ctxs,p__12830);
});
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__12858){var vec__12864 = p__12858;var obj = cljs.core.nth.call(null,vec__12864,0,null);var seq__12865 = cljs.core.seq.call(null,ctxs);var chunk__12866 = null;var count__12867 = 0;var i__12868 = 0;while(true){
if((i__12868 < count__12867))
{var c = cljs.core._nth.call(null,chunk__12866,i__12868);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__12869 = seq__12865;
var G__12870 = chunk__12866;
var G__12871 = count__12867;
var G__12872 = (i__12868 + 1);
seq__12865 = G__12869;
chunk__12866 = G__12870;
count__12867 = G__12871;
i__12868 = G__12872;
continue;
}
} else
{var temp__4092__auto__ = cljs.core.seq.call(null,seq__12865);if(temp__4092__auto__)
{var seq__12865__$1 = temp__4092__auto__;if(cljs.core.chunked_seq_QMARK_.call(null,seq__12865__$1))
{var c__4262__auto__ = cljs.core.chunk_first.call(null,seq__12865__$1);{
var G__12873 = cljs.core.chunk_rest.call(null,seq__12865__$1);
var G__12874 = c__4262__auto__;
var G__12875 = cljs.core.count.call(null,c__4262__auto__);
var G__12876 = 0;
seq__12865 = G__12873;
chunk__12866 = G__12874;
count__12867 = G__12875;
i__12868 = G__12876;
continue;
}
} else
{var c = cljs.core.first.call(null,seq__12865__$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__12877 = cljs.core.next.call(null,seq__12865__$1);
var G__12878 = null;
var G__12879 = 0;
var G__12880 = 0;
seq__12865 = G__12877;
chunk__12866 = G__12878;
count__12867 = G__12879;
i__12868 = G__12880;
continue;
}
}
} else
{return null;
}
}
break;
}
};
var toggle_BANG_ = function (ctxs,var_args){
var p__12858 = null;if (arguments.length > 1) {
  p__12858 = cljs.core.array_seq(Array.prototype.slice.call(arguments, 1),0);} 
return toggle_BANG___delegate.call(this,ctxs,p__12858);};
toggle_BANG_.cljs$lang$maxFixedArity = 1;
toggle_BANG_.cljs$lang$applyTo = (function (arglist__12881){
var ctxs = cljs.core.first(arglist__12881);
var p__12858 = cljs.core.rest(arglist__12881);
return toggle_BANG___delegate(ctxs,p__12858);
});
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__12882_SHARP_){return lt.objs.context.enqueue.call(null,ctx,p1__12882_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));
