// Compiled by ClojureScript 1.10.520 {}
goog.provide('rum.derived_atom');
goog.require('cljs.core');
rum.derived_atom.derived_atom = (function rum$derived_atom$derived_atom(var_args){
var G__32229 = arguments.length;
switch (G__32229) {
case 3:
return rum.derived_atom.derived_atom.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)]));

break;
case 4:
return rum.derived_atom.derived_atom.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]));

break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));

}
});

rum.derived_atom.derived_atom.cljs$core$IFn$_invoke$arity$3 = (function (refs,key,f){
return rum.derived_atom.derived_atom.call(null,refs,key,f,cljs.core.PersistentArrayMap.EMPTY);
});

rum.derived_atom.derived_atom.cljs$core$IFn$_invoke$arity$4 = (function (refs,key,f,opts){
var map__32230 = opts;
var map__32230__$1 = (((((!((map__32230 == null))))?(((((map__32230.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__32230.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__32230):map__32230);
var ref = cljs.core.get.call(null,map__32230__$1,new cljs.core.Keyword(null,"ref","ref",1289896967));
var check_equals_QMARK_ = cljs.core.get.call(null,map__32230__$1,new cljs.core.Keyword(null,"check-equals?","check-equals?",-2005755315),true);
var recalc = (function (){var G__32232 = cljs.core.count.call(null,refs);
switch (G__32232) {
case (1):
var vec__32233 = refs;
var a = cljs.core.nth.call(null,vec__32233,(0),null);
return ((function (vec__32233,a,G__32232,map__32230,map__32230__$1,ref,check_equals_QMARK_){
return (function (){
return f.call(null,cljs.core.deref.call(null,a));
});
;})(vec__32233,a,G__32232,map__32230,map__32230__$1,ref,check_equals_QMARK_))

break;
case (2):
var vec__32236 = refs;
var a = cljs.core.nth.call(null,vec__32236,(0),null);
var b = cljs.core.nth.call(null,vec__32236,(1),null);
return ((function (vec__32236,a,b,G__32232,map__32230,map__32230__$1,ref,check_equals_QMARK_){
return (function (){
return f.call(null,cljs.core.deref.call(null,a),cljs.core.deref.call(null,b));
});
;})(vec__32236,a,b,G__32232,map__32230,map__32230__$1,ref,check_equals_QMARK_))

break;
case (3):
var vec__32239 = refs;
var a = cljs.core.nth.call(null,vec__32239,(0),null);
var b = cljs.core.nth.call(null,vec__32239,(1),null);
var c = cljs.core.nth.call(null,vec__32239,(2),null);
return ((function (vec__32239,a,b,c,G__32232,map__32230,map__32230__$1,ref,check_equals_QMARK_){
return (function (){
return f.call(null,cljs.core.deref.call(null,a),cljs.core.deref.call(null,b),cljs.core.deref.call(null,c));
});
;})(vec__32239,a,b,c,G__32232,map__32230,map__32230__$1,ref,check_equals_QMARK_))

break;
default:
return ((function (G__32232,map__32230,map__32230__$1,ref,check_equals_QMARK_){
return (function (){
return cljs.core.apply.call(null,f,cljs.core.map.call(null,cljs.core.deref,refs));
});
;})(G__32232,map__32230,map__32230__$1,ref,check_equals_QMARK_))

}
})();
var sink = (cljs.core.truth_(ref)?(function (){var G__32242 = ref;
cljs.core.reset_BANG_.call(null,G__32242,recalc.call(null));

return G__32242;
})():cljs.core.atom.call(null,recalc.call(null)));
var watch = (cljs.core.truth_(check_equals_QMARK_)?((function (map__32230,map__32230__$1,ref,check_equals_QMARK_,recalc,sink){
return (function (_,___$1,___$2,___$3){
var new_val = recalc.call(null);
if(cljs.core.not_EQ_.call(null,cljs.core.deref.call(null,sink),new_val)){
return cljs.core.reset_BANG_.call(null,sink,new_val);
} else {
return null;
}
});})(map__32230,map__32230__$1,ref,check_equals_QMARK_,recalc,sink))
:((function (map__32230,map__32230__$1,ref,check_equals_QMARK_,recalc,sink){
return (function (_,___$1,___$2,___$3){
return cljs.core.reset_BANG_.call(null,sink,recalc.call(null));
});})(map__32230,map__32230__$1,ref,check_equals_QMARK_,recalc,sink))
);
var seq__32243_32249 = cljs.core.seq.call(null,refs);
var chunk__32244_32250 = null;
var count__32245_32251 = (0);
var i__32246_32252 = (0);
while(true){
if((i__32246_32252 < count__32245_32251)){
var ref_32253__$1 = cljs.core._nth.call(null,chunk__32244_32250,i__32246_32252);
cljs.core.add_watch.call(null,ref_32253__$1,key,watch);


var G__32254 = seq__32243_32249;
var G__32255 = chunk__32244_32250;
var G__32256 = count__32245_32251;
var G__32257 = (i__32246_32252 + (1));
seq__32243_32249 = G__32254;
chunk__32244_32250 = G__32255;
count__32245_32251 = G__32256;
i__32246_32252 = G__32257;
continue;
} else {
var temp__5720__auto___32258 = cljs.core.seq.call(null,seq__32243_32249);
if(temp__5720__auto___32258){
var seq__32243_32259__$1 = temp__5720__auto___32258;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__32243_32259__$1)){
var c__4550__auto___32260 = cljs.core.chunk_first.call(null,seq__32243_32259__$1);
var G__32261 = cljs.core.chunk_rest.call(null,seq__32243_32259__$1);
var G__32262 = c__4550__auto___32260;
var G__32263 = cljs.core.count.call(null,c__4550__auto___32260);
var G__32264 = (0);
seq__32243_32249 = G__32261;
chunk__32244_32250 = G__32262;
count__32245_32251 = G__32263;
i__32246_32252 = G__32264;
continue;
} else {
var ref_32265__$1 = cljs.core.first.call(null,seq__32243_32259__$1);
cljs.core.add_watch.call(null,ref_32265__$1,key,watch);


var G__32266 = cljs.core.next.call(null,seq__32243_32259__$1);
var G__32267 = null;
var G__32268 = (0);
var G__32269 = (0);
seq__32243_32249 = G__32266;
chunk__32244_32250 = G__32267;
count__32245_32251 = G__32268;
i__32246_32252 = G__32269;
continue;
}
} else {
}
}
break;
}

return sink;
});

rum.derived_atom.derived_atom.cljs$lang$maxFixedArity = 4;

