goog.provide('re_frame.trace');
re_frame.trace.id = cljs.core.atom.cljs$core$IFn$_invoke$arity$1((0));
re_frame.trace._STAR_current_trace_STAR_ = null;
re_frame.trace.reset_tracing_BANG_ = (function re_frame$trace$reset_tracing_BANG_(){
return cljs.core.reset_BANG_(re_frame.trace.id,(0));
});
/**
 * @define {boolean}
 */
re_frame.trace.trace_enabled_QMARK_ = goog.define("re_frame.trace.trace_enabled_QMARK_",false);
/**
 * See https://groups.google.com/d/msg/clojurescript/jk43kmYiMhA/IHglVr_TPdgJ for more details
 */
re_frame.trace.is_trace_enabled_QMARK_ = (function re_frame$trace$is_trace_enabled_QMARK_(){
return re_frame.trace.trace_enabled_QMARK_;
});
re_frame.trace.trace_cbs = cljs.core.atom.cljs$core$IFn$_invoke$arity$1(cljs.core.PersistentArrayMap.EMPTY);
if((typeof re_frame !== 'undefined') && (typeof re_frame.trace !== 'undefined') && (typeof re_frame.trace.traces !== 'undefined')){
} else {
re_frame.trace.traces = cljs.core.atom.cljs$core$IFn$_invoke$arity$1(cljs.core.PersistentVector.EMPTY);
}
if((typeof re_frame !== 'undefined') && (typeof re_frame.trace !== 'undefined') && (typeof re_frame.trace.next_delivery !== 'undefined')){
} else {
re_frame.trace.next_delivery = cljs.core.atom.cljs$core$IFn$_invoke$arity$1((0));
}
/**
 * Registers a tracing callback function which will receive a collection of one or more traces.
 *   Will replace an existing callback function if it shares the same key.
 */
re_frame.trace.register_trace_cb = (function re_frame$trace$register_trace_cb(key,f){
if(re_frame.trace.trace_enabled_QMARK_){
return cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$4(re_frame.trace.trace_cbs,cljs.core.assoc,key,f);
} else {
return re_frame.loggers.console.cljs$core$IFn$_invoke$arity$variadic(new cljs.core.Keyword(null,"warn","warn",-436710552),cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["Tracing is not enabled. Please set {\"re_frame.trace.trace_enabled_QMARK_\" true} in :closure-defines. See: https://github.com/day8/re-frame-10x#installation."], 0));
}
});
re_frame.trace.remove_trace_cb = (function re_frame$trace$remove_trace_cb(key){
cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$3(re_frame.trace.trace_cbs,cljs.core.dissoc,key);

return null;
});
re_frame.trace.next_id = (function re_frame$trace$next_id(){
return cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$2(re_frame.trace.id,cljs.core.inc);
});
re_frame.trace.start_trace = (function re_frame$trace$start_trace(p__52743){
var map__52744 = p__52743;
var map__52744__$1 = cljs.core.__destructure_map(map__52744);
var operation = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__52744__$1,new cljs.core.Keyword(null,"operation","operation",-1267664310));
var op_type = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__52744__$1,new cljs.core.Keyword(null,"op-type","op-type",-1636141668));
var tags = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__52744__$1,new cljs.core.Keyword(null,"tags","tags",1771418977));
var child_of = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__52744__$1,new cljs.core.Keyword(null,"child-of","child-of",-903376662));
return new cljs.core.PersistentArrayMap(null, 6, [new cljs.core.Keyword(null,"id","id",-1388402092),re_frame.trace.next_id(),new cljs.core.Keyword(null,"operation","operation",-1267664310),operation,new cljs.core.Keyword(null,"op-type","op-type",-1636141668),op_type,new cljs.core.Keyword(null,"tags","tags",1771418977),tags,new cljs.core.Keyword(null,"child-of","child-of",-903376662),(function (){var or__5025__auto__ = child_of;
if(cljs.core.truth_(or__5025__auto__)){
return or__5025__auto__;
} else {
return new cljs.core.Keyword(null,"id","id",-1388402092).cljs$core$IFn$_invoke$arity$1(re_frame.trace._STAR_current_trace_STAR_);
}
})(),new cljs.core.Keyword(null,"start","start",-355208981),re_frame.interop.now()], null);
});
re_frame.trace.debounce_time = (50);
re_frame.trace.debounce = (function re_frame$trace$debounce(f,interval){
return goog.functions.debounce(f,interval);
});
re_frame.trace.schedule_debounce = re_frame.trace.debounce((function re_frame$trace$tracing_cb_debounced(){
var seq__52746_52779 = cljs.core.seq(cljs.core.deref(re_frame.trace.trace_cbs));
var chunk__52747_52780 = null;
var count__52748_52781 = (0);
var i__52749_52782 = (0);
while(true){
if((i__52749_52782 < count__52748_52781)){
var vec__52762_52784 = chunk__52747_52780.cljs$core$IIndexed$_nth$arity$2(null,i__52749_52782);
var k_52785 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__52762_52784,(0),null);
var cb_52786 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__52762_52784,(1),null);
try{var G__52766_52787 = cljs.core.deref(re_frame.trace.traces);
(cb_52786.cljs$core$IFn$_invoke$arity$1 ? cb_52786.cljs$core$IFn$_invoke$arity$1(G__52766_52787) : cb_52786.call(null,G__52766_52787));
}catch (e52765){var e_52788 = e52765;
re_frame.loggers.console.cljs$core$IFn$_invoke$arity$variadic(new cljs.core.Keyword(null,"error","error",-978969032),cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["Error thrown from trace cb",k_52785,"while storing",cljs.core.deref(re_frame.trace.traces),e_52788], 0));
}

var G__52789 = seq__52746_52779;
var G__52790 = chunk__52747_52780;
var G__52791 = count__52748_52781;
var G__52792 = (i__52749_52782 + (1));
seq__52746_52779 = G__52789;
chunk__52747_52780 = G__52790;
count__52748_52781 = G__52791;
i__52749_52782 = G__52792;
continue;
} else {
var temp__5804__auto___52793 = cljs.core.seq(seq__52746_52779);
if(temp__5804__auto___52793){
var seq__52746_52794__$1 = temp__5804__auto___52793;
if(cljs.core.chunked_seq_QMARK_(seq__52746_52794__$1)){
var c__5548__auto___52795 = cljs.core.chunk_first(seq__52746_52794__$1);
var G__52796 = cljs.core.chunk_rest(seq__52746_52794__$1);
var G__52797 = c__5548__auto___52795;
var G__52798 = cljs.core.count(c__5548__auto___52795);
var G__52799 = (0);
seq__52746_52779 = G__52796;
chunk__52747_52780 = G__52797;
count__52748_52781 = G__52798;
i__52749_52782 = G__52799;
continue;
} else {
var vec__52767_52800 = cljs.core.first(seq__52746_52794__$1);
var k_52801 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__52767_52800,(0),null);
var cb_52802 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__52767_52800,(1),null);
try{var G__52772_52803 = cljs.core.deref(re_frame.trace.traces);
(cb_52802.cljs$core$IFn$_invoke$arity$1 ? cb_52802.cljs$core$IFn$_invoke$arity$1(G__52772_52803) : cb_52802.call(null,G__52772_52803));
}catch (e52770){var e_52804 = e52770;
re_frame.loggers.console.cljs$core$IFn$_invoke$arity$variadic(new cljs.core.Keyword(null,"error","error",-978969032),cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["Error thrown from trace cb",k_52801,"while storing",cljs.core.deref(re_frame.trace.traces),e_52804], 0));
}

var G__52805 = cljs.core.next(seq__52746_52794__$1);
var G__52806 = null;
var G__52807 = (0);
var G__52808 = (0);
seq__52746_52779 = G__52805;
chunk__52747_52780 = G__52806;
count__52748_52781 = G__52807;
i__52749_52782 = G__52808;
continue;
}
} else {
}
}
break;
}

return cljs.core.reset_BANG_(re_frame.trace.traces,cljs.core.PersistentVector.EMPTY);
}),re_frame.trace.debounce_time);
re_frame.trace.run_tracing_callbacks_BANG_ = (function re_frame$trace$run_tracing_callbacks_BANG_(now){
if(((cljs.core.deref(re_frame.trace.next_delivery) - (25)) < now)){
(re_frame.trace.schedule_debounce.cljs$core$IFn$_invoke$arity$0 ? re_frame.trace.schedule_debounce.cljs$core$IFn$_invoke$arity$0() : re_frame.trace.schedule_debounce.call(null));

return cljs.core.reset_BANG_(re_frame.trace.next_delivery,(now + re_frame.trace.debounce_time));
} else {
return null;
}
});

//# sourceMappingURL=re_frame.trace.js.map
