// Compiled by ClojureScript 0.0-2138
goog.provide('crate.binding');
goog.require('cljs.core');
goog.require('clojure.set');
goog.require('clojure.set');

/**
* @constructor
*/
crate.binding.SubAtom = (function (atm,path,prevhash,watches,key){
this.atm = atm;
this.path = path;
this.prevhash = prevhash;
this.watches = watches;
this.key = key;
this.cljs$lang$protocol_mask$partition0$ = 2153807872;
this.cljs$lang$protocol_mask$partition1$ = 2;
})
crate.binding.SubAtom.cljs$lang$type = true;
crate.binding.SubAtom.cljs$lang$ctorStr = "crate.binding/SubAtom";
crate.binding.SubAtom.cljs$lang$ctorPrWriter = (function (this__4082__auto__,writer__4083__auto__,opt__4084__auto__){return cljs.core._write.call(null,writer__4083__auto__,"crate.binding/SubAtom");
});
crate.binding.SubAtom.prototype.cljs$core$IHash$_hash$arity$1 = (function (this$){var self__ = this;
var this$__$1 = this;return goog.getUid(this$__$1);
});
crate.binding.SubAtom.prototype.cljs$core$IWatchable$_notify_watches$arity$3 = (function (this$,oldval,newval){var self__ = this;
var this$__$1 = this;var seq__15756 = cljs.core.seq.call(null,self__.watches);var chunk__15757 = null;var count__15758 = 0;var i__15759 = 0;while(true){
if((i__15759 < count__15758))
{var vec__15760 = cljs.core._nth.call(null,chunk__15757,i__15759);var key__$1 = cljs.core.nth.call(null,vec__15760,0,null);var f = cljs.core.nth.call(null,vec__15760,1,null);f.call(null,key__$1,this$__$1,oldval,newval);
{
var G__15762 = seq__15756;
var G__15763 = chunk__15757;
var G__15764 = count__15758;
var G__15765 = (i__15759 + 1);
seq__15756 = G__15762;
chunk__15757 = G__15763;
count__15758 = G__15764;
i__15759 = G__15765;
continue;
}
} else
{var temp__4092__auto__ = cljs.core.seq.call(null,seq__15756);if(temp__4092__auto__)
{var seq__15756__$1 = temp__4092__auto__;if(cljs.core.chunked_seq_QMARK_.call(null,seq__15756__$1))
{var c__4262__auto__ = cljs.core.chunk_first.call(null,seq__15756__$1);{
var G__15766 = cljs.core.chunk_rest.call(null,seq__15756__$1);
var G__15767 = c__4262__auto__;
var G__15768 = cljs.core.count.call(null,c__4262__auto__);
var G__15769 = 0;
seq__15756 = G__15766;
chunk__15757 = G__15767;
count__15758 = G__15768;
i__15759 = G__15769;
continue;
}
} else
{var vec__15761 = cljs.core.first.call(null,seq__15756__$1);var key__$1 = cljs.core.nth.call(null,vec__15761,0,null);var f = cljs.core.nth.call(null,vec__15761,1,null);f.call(null,key__$1,this$__$1,oldval,newval);
{
var G__15770 = cljs.core.next.call(null,seq__15756__$1);
var G__15771 = null;
var G__15772 = 0;
var G__15773 = 0;
seq__15756 = G__15770;
chunk__15757 = G__15771;
count__15758 = G__15772;
i__15759 = G__15773;
continue;
}
}
} else
{return null;
}
}
break;
}
});
crate.binding.SubAtom.prototype.cljs$core$IWatchable$_add_watch$arity$3 = (function (this$,key__$1,f){var self__ = this;
var this$__$1 = this;if(cljs.core.truth_(f))
{return this$__$1.watches = cljs.core.assoc.call(null,self__.watches,key__$1,f);
} else
{return null;
}
});
crate.binding.SubAtom.prototype.cljs$core$IWatchable$_remove_watch$arity$2 = (function (this$,key__$1){var self__ = this;
var this$__$1 = this;return this$__$1.watches = cljs.core.dissoc.call(null,self__.watches,key__$1);
});
crate.binding.SubAtom.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (this$,writer,opts){var self__ = this;
var this$__$1 = this;return cljs.core._write.call(null,writer,[cljs.core.str("#<SubAtom: "),cljs.core.str(cljs.core.pr_str.call(null,cljs.core.get_in.call(null,cljs.core.deref.call(null,self__.atm),self__.path))),cljs.core.str(">")].join(''));
});
crate.binding.SubAtom.prototype.cljs$core$IDeref$_deref$arity$1 = (function (_){var self__ = this;
var ___$1 = this;if(cljs.core.truth_(self__.atm))
{return cljs.core.get_in.call(null,cljs.core.deref.call(null,self__.atm),self__.path);
} else
{return null;
}
});
crate.binding.SubAtom.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (o,other){var self__ = this;
var o__$1 = this;return (o__$1 === other);
});
crate.binding.__GT_SubAtom = (function __GT_SubAtom(atm,path,prevhash,watches,key){return (new crate.binding.SubAtom(atm,path,prevhash,watches,key));
});
crate.binding.subatom = (function subatom(atm,path){var path__$1 = ((cljs.core.coll_QMARK_.call(null,path))?path:new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [path], null));var vec__15775 = (((atm instanceof crate.binding.SubAtom))?new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [atm.atm,cljs.core.concat.call(null,atm.path,path__$1)], null):new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [atm,path__$1], null));var atm__$1 = cljs.core.nth.call(null,vec__15775,0,null);var path__$2 = cljs.core.nth.call(null,vec__15775,1,null);var k = cljs.core.gensym.call(null,"subatom");var sa = (new crate.binding.SubAtom(atm__$1,path__$2,cljs.core.hash.call(null,cljs.core.get_in.call(null,cljs.core.deref.call(null,atm__$1),path__$2)),null,k));cljs.core.add_watch.call(null,atm__$1,k,(function (_,___$1,ov,nv){var latest = cljs.core.get_in.call(null,nv,path__$2);var prev = cljs.core.get_in.call(null,ov,path__$2);var latest_hash = cljs.core.hash.call(null,latest);if((cljs.core.not_EQ_.call(null,sa.prevhash,latest_hash)) && (cljs.core.not_EQ_.call(null,prev,latest)))
{sa.prevhash = latest_hash;
return cljs.core._notify_watches.call(null,sa,cljs.core.get_in.call(null,ov,path__$2),latest);
} else
{return null;
}
}));
return sa;
});
/**
* Sets the value of atom to newval without regard for the
* current value. Returns newval.
*/
crate.binding.sub_reset_BANG_ = (function sub_reset_BANG_(sa,new_value){cljs.core.swap_BANG_.call(null,sa.atm,cljs.core.assoc_in,sa.path,new_value);
return new_value;
});
/**
* Atomically swaps the value of atom to be:
* (apply f current-value-of-atom args). Note that f may be called
* multiple times, and thus should be free of side effects.  Returns
* the value that was swapped in.
* @param {...*} var_args
*/
crate.binding.sub_swap_BANG_ = (function() {
var sub_swap_BANG_ = null;
var sub_swap_BANG___2 = (function (sa,f){return crate.binding.sub_reset_BANG_.call(null,sa,f.call(null,cljs.core.deref.call(null,sa)));
});
var sub_swap_BANG___3 = (function (sa,f,x){return crate.binding.sub_reset_BANG_.call(null,sa,f.call(null,cljs.core.deref.call(null,sa),x));
});
var sub_swap_BANG___4 = (function (sa,f,x,y){return crate.binding.sub_reset_BANG_.call(null,sa,f.call(null,cljs.core.deref.call(null,sa),x,y));
});
var sub_swap_BANG___5 = (function (sa,f,x,y,z){return crate.binding.sub_reset_BANG_.call(null,sa,f.call(null,cljs.core.deref.call(null,sa),x,y,z));
});
var sub_swap_BANG___6 = (function() { 
var G__15776__delegate = function (sa,f,x,y,z,more){return crate.binding.sub_reset_BANG_.call(null,sa,cljs.core.apply.call(null,f,cljs.core.deref.call(null,sa),x,y,z,more));
};
var G__15776 = function (sa,f,x,y,z,var_args){
var more = null;if (arguments.length > 5) {
  more = cljs.core.array_seq(Array.prototype.slice.call(arguments, 5),0);} 
return G__15776__delegate.call(this,sa,f,x,y,z,more);};
G__15776.cljs$lang$maxFixedArity = 5;
G__15776.cljs$lang$applyTo = (function (arglist__15777){
var sa = cljs.core.first(arglist__15777);
arglist__15777 = cljs.core.next(arglist__15777);
var f = cljs.core.first(arglist__15777);
arglist__15777 = cljs.core.next(arglist__15777);
var x = cljs.core.first(arglist__15777);
arglist__15777 = cljs.core.next(arglist__15777);
var y = cljs.core.first(arglist__15777);
arglist__15777 = cljs.core.next(arglist__15777);
var z = cljs.core.first(arglist__15777);
var more = cljs.core.rest(arglist__15777);
return G__15776__delegate(sa,f,x,y,z,more);
});
G__15776.cljs$core$IFn$_invoke$arity$variadic = G__15776__delegate;
return G__15776;
})()
;
sub_swap_BANG_ = function(sa,f,x,y,z,var_args){
var more = var_args;
switch(arguments.length){
case 2:
return sub_swap_BANG___2.call(this,sa,f);
case 3:
return sub_swap_BANG___3.call(this,sa,f,x);
case 4:
return sub_swap_BANG___4.call(this,sa,f,x,y);
case 5:
return sub_swap_BANG___5.call(this,sa,f,x,y,z);
default:
return sub_swap_BANG___6.cljs$core$IFn$_invoke$arity$variadic(sa,f,x,y,z, cljs.core.array_seq(arguments, 5));
}
throw(new Error('Invalid arity: ' + arguments.length));
};
sub_swap_BANG_.cljs$lang$maxFixedArity = 5;
sub_swap_BANG_.cljs$lang$applyTo = sub_swap_BANG___6.cljs$lang$applyTo;
sub_swap_BANG_.cljs$core$IFn$_invoke$arity$2 = sub_swap_BANG___2;
sub_swap_BANG_.cljs$core$IFn$_invoke$arity$3 = sub_swap_BANG___3;
sub_swap_BANG_.cljs$core$IFn$_invoke$arity$4 = sub_swap_BANG___4;
sub_swap_BANG_.cljs$core$IFn$_invoke$arity$5 = sub_swap_BANG___5;
sub_swap_BANG_.cljs$core$IFn$_invoke$arity$variadic = sub_swap_BANG___6.cljs$core$IFn$_invoke$arity$variadic;
return sub_swap_BANG_;
})()
;
crate.binding.sub_destroy_BANG_ = (function sub_destroy_BANG_(sa){cljs.core.remove_watch.call(null,sa.atm,sa.key);
sa.watches = null;
return sa.atm = null;
});
crate.binding.computable = (function (){var obj15779 = {};return obj15779;
})();
crate.binding._depend = (function _depend(this$,atm){if((function (){var and__3508__auto__ = this$;if(and__3508__auto__)
{return this$.crate$binding$computable$_depend$arity$2;
} else
{return and__3508__auto__;
}
})())
{return this$.crate$binding$computable$_depend$arity$2(this$,atm);
} else
{var x__4141__auto__ = (((this$ == null))?null:this$);return (function (){var or__3520__auto__ = (crate.binding._depend[goog.typeOf(x__4141__auto__)]);if(or__3520__auto__)
{return or__3520__auto__;
} else
{var or__3520__auto____$1 = (crate.binding._depend["_"]);if(or__3520__auto____$1)
{return or__3520__auto____$1;
} else
{throw cljs.core.missing_protocol.call(null,"computable.-depend",this$);
}
}
})().call(null,this$,atm);
}
});
crate.binding._compute = (function _compute(this$){if((function (){var and__3508__auto__ = this$;if(and__3508__auto__)
{return this$.crate$binding$computable$_compute$arity$1;
} else
{return and__3508__auto__;
}
})())
{return this$.crate$binding$computable$_compute$arity$1(this$);
} else
{var x__4141__auto__ = (((this$ == null))?null:this$);return (function (){var or__3520__auto__ = (crate.binding._compute[goog.typeOf(x__4141__auto__)]);if(or__3520__auto__)
{return or__3520__auto__;
} else
{var or__3520__auto____$1 = (crate.binding._compute["_"]);if(or__3520__auto____$1)
{return or__3520__auto____$1;
} else
{throw cljs.core.missing_protocol.call(null,"computable.-compute",this$);
}
}
})().call(null,this$);
}
});

/**
* @constructor
*/
crate.binding.Computed = (function (atms,value,func,watches,key,meta){
this.atms = atms;
this.value = value;
this.func = func;
this.watches = watches;
this.key = key;
this.meta = meta;
this.cljs$lang$protocol_mask$partition0$ = 2153938944;
this.cljs$lang$protocol_mask$partition1$ = 2;
})
crate.binding.Computed.cljs$lang$type = true;
crate.binding.Computed.cljs$lang$ctorStr = "crate.binding/Computed";
crate.binding.Computed.cljs$lang$ctorPrWriter = (function (this__4082__auto__,writer__4083__auto__,opt__4084__auto__){return cljs.core._write.call(null,writer__4083__auto__,"crate.binding/Computed");
});
crate.binding.Computed.prototype.crate$binding$computable$ = true;
crate.binding.Computed.prototype.crate$binding$computable$_depend$arity$2 = (function (this$,atm){var self__ = this;
var this$__$1 = this;this$__$1.atms = cljs.core.conj.call(null,this$__$1.atms,atm);
return cljs.core.add_watch.call(null,atm,self__.key,(function (_,___$1,___$2,___$3){return crate.binding._compute.call(null,this$__$1);
}));
});
crate.binding.Computed.prototype.crate$binding$computable$_compute$arity$1 = (function (this$){var self__ = this;
var this$__$1 = this;var old = this$__$1.value;var nv = cljs.core.apply.call(null,self__.func,cljs.core.map.call(null,cljs.core.deref,self__.atms));this$__$1.value = nv;
return cljs.core._notify_watches.call(null,this$__$1,old,nv);
});
crate.binding.Computed.prototype.cljs$core$IMeta$_meta$arity$1 = (function (this$){var self__ = this;
var this$__$1 = this;return self__.meta;
});
crate.binding.Computed.prototype.cljs$core$IHash$_hash$arity$1 = (function (this$){var self__ = this;
var this$__$1 = this;return goog.getUid(this$__$1);
});
crate.binding.Computed.prototype.cljs$core$IWatchable$_notify_watches$arity$3 = (function (this$,oldval,newval){var self__ = this;
var this$__$1 = this;var seq__15780 = cljs.core.seq.call(null,self__.watches);var chunk__15781 = null;var count__15782 = 0;var i__15783 = 0;while(true){
if((i__15783 < count__15782))
{var vec__15784 = cljs.core._nth.call(null,chunk__15781,i__15783);var key__$1 = cljs.core.nth.call(null,vec__15784,0,null);var f = cljs.core.nth.call(null,vec__15784,1,null);f.call(null,key__$1,this$__$1,oldval,newval);
{
var G__15786 = seq__15780;
var G__15787 = chunk__15781;
var G__15788 = count__15782;
var G__15789 = (i__15783 + 1);
seq__15780 = G__15786;
chunk__15781 = G__15787;
count__15782 = G__15788;
i__15783 = G__15789;
continue;
}
} else
{var temp__4092__auto__ = cljs.core.seq.call(null,seq__15780);if(temp__4092__auto__)
{var seq__15780__$1 = temp__4092__auto__;if(cljs.core.chunked_seq_QMARK_.call(null,seq__15780__$1))
{var c__4262__auto__ = cljs.core.chunk_first.call(null,seq__15780__$1);{
var G__15790 = cljs.core.chunk_rest.call(null,seq__15780__$1);
var G__15791 = c__4262__auto__;
var G__15792 = cljs.core.count.call(null,c__4262__auto__);
var G__15793 = 0;
seq__15780 = G__15790;
chunk__15781 = G__15791;
count__15782 = G__15792;
i__15783 = G__15793;
continue;
}
} else
{var vec__15785 = cljs.core.first.call(null,seq__15780__$1);var key__$1 = cljs.core.nth.call(null,vec__15785,0,null);var f = cljs.core.nth.call(null,vec__15785,1,null);f.call(null,key__$1,this$__$1,oldval,newval);
{
var G__15794 = cljs.core.next.call(null,seq__15780__$1);
var G__15795 = null;
var G__15796 = 0;
var G__15797 = 0;
seq__15780 = G__15794;
chunk__15781 = G__15795;
count__15782 = G__15796;
i__15783 = G__15797;
continue;
}
}
} else
{return null;
}
}
break;
}
});
crate.binding.Computed.prototype.cljs$core$IWatchable$_add_watch$arity$3 = (function (this$,key__$1,f){var self__ = this;
var this$__$1 = this;if(cljs.core.truth_(f))
{return this$__$1.watches = cljs.core.assoc.call(null,self__.watches,key__$1,f);
} else
{return null;
}
});
crate.binding.Computed.prototype.cljs$core$IWatchable$_remove_watch$arity$2 = (function (this$,key__$1){var self__ = this;
var this$__$1 = this;return this$__$1.watches = cljs.core.dissoc.call(null,self__.watches,key__$1);
});
crate.binding.Computed.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (this$,writer,opts){var self__ = this;
var this$__$1 = this;return cljs.core._write.call(null,writer,[cljs.core.str("#<Computed: "),cljs.core.str(cljs.core.pr_str.call(null,self__.value)),cljs.core.str(">")].join(''));
});
crate.binding.Computed.prototype.cljs$core$IDeref$_deref$arity$1 = (function (_){var self__ = this;
var ___$1 = this;return self__.value;
});
crate.binding.Computed.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (o,other){var self__ = this;
var o__$1 = this;return (o__$1 === other);
});
crate.binding.__GT_Computed = (function __GT_Computed(atms,value,func,watches,key,meta){return (new crate.binding.Computed(atms,value,func,watches,key,meta));
});
crate.binding.computed = (function computed(atms,func){var k = cljs.core.gensym.call(null,"computed");var neue = (new crate.binding.Computed(cljs.core.PersistentVector.EMPTY,null,func,null,k,null));crate.binding._compute.call(null,neue);
var seq__15802_15806 = cljs.core.seq.call(null,atms);var chunk__15803_15807 = null;var count__15804_15808 = 0;var i__15805_15809 = 0;while(true){
if((i__15805_15809 < count__15804_15808))
{var atm_15810 = cljs.core._nth.call(null,chunk__15803_15807,i__15805_15809);crate.binding._depend.call(null,neue,atm_15810);
{
var G__15811 = seq__15802_15806;
var G__15812 = chunk__15803_15807;
var G__15813 = count__15804_15808;
var G__15814 = (i__15805_15809 + 1);
seq__15802_15806 = G__15811;
chunk__15803_15807 = G__15812;
count__15804_15808 = G__15813;
i__15805_15809 = G__15814;
continue;
}
} else
{var temp__4092__auto___15815 = cljs.core.seq.call(null,seq__15802_15806);if(temp__4092__auto___15815)
{var seq__15802_15816__$1 = temp__4092__auto___15815;if(cljs.core.chunked_seq_QMARK_.call(null,seq__15802_15816__$1))
{var c__4262__auto___15817 = cljs.core.chunk_first.call(null,seq__15802_15816__$1);{
var G__15818 = cljs.core.chunk_rest.call(null,seq__15802_15816__$1);
var G__15819 = c__4262__auto___15817;
var G__15820 = cljs.core.count.call(null,c__4262__auto___15817);
var G__15821 = 0;
seq__15802_15806 = G__15818;
chunk__15803_15807 = G__15819;
count__15804_15808 = G__15820;
i__15805_15809 = G__15821;
continue;
}
} else
{var atm_15822 = cljs.core.first.call(null,seq__15802_15816__$1);crate.binding._depend.call(null,neue,atm_15822);
{
var G__15823 = cljs.core.next.call(null,seq__15802_15816__$1);
var G__15824 = null;
var G__15825 = 0;
var G__15826 = 0;
seq__15802_15806 = G__15823;
chunk__15803_15807 = G__15824;
count__15804_15808 = G__15825;
i__15805_15809 = G__15826;
continue;
}
}
} else
{}
}
break;
}
return neue;
});
crate.binding.compute = (function compute(compu){return crate.binding._compute.call(null,compu);
});
crate.binding.depend_on = (function depend_on(compu,atm){return crate.binding._depend.call(null,compu,atm);
});
crate.binding.notify = (function notify(w,o,v){return cljs.core._notify_watches.call(null,w,o,v);
});
crate.binding.bindable_coll = (function (){var obj15828 = {};return obj15828;
})();
crate.binding.bindable = (function (){var obj15830 = {};return obj15830;
})();
crate.binding._value = (function _value(this$){if((function (){var and__3508__auto__ = this$;if(and__3508__auto__)
{return this$.crate$binding$bindable$_value$arity$1;
} else
{return and__3508__auto__;
}
})())
{return this$.crate$binding$bindable$_value$arity$1(this$);
} else
{var x__4141__auto__ = (((this$ == null))?null:this$);return (function (){var or__3520__auto__ = (crate.binding._value[goog.typeOf(x__4141__auto__)]);if(or__3520__auto__)
{return or__3520__auto__;
} else
{var or__3520__auto____$1 = (crate.binding._value["_"]);if(or__3520__auto____$1)
{return or__3520__auto____$1;
} else
{throw cljs.core.missing_protocol.call(null,"bindable.-value",this$);
}
}
})().call(null,this$);
}
});
crate.binding._on_change = (function _on_change(this$,func){if((function (){var and__3508__auto__ = this$;if(and__3508__auto__)
{return this$.crate$binding$bindable$_on_change$arity$2;
} else
{return and__3508__auto__;
}
})())
{return this$.crate$binding$bindable$_on_change$arity$2(this$,func);
} else
{var x__4141__auto__ = (((this$ == null))?null:this$);return (function (){var or__3520__auto__ = (crate.binding._on_change[goog.typeOf(x__4141__auto__)]);if(or__3520__auto__)
{return or__3520__auto__;
} else
{var or__3520__auto____$1 = (crate.binding._on_change["_"]);if(or__3520__auto____$1)
{return or__3520__auto____$1;
} else
{throw cljs.core.missing_protocol.call(null,"bindable.-on-change",this$);
}
}
})().call(null,this$,func);
}
});

/**
* @constructor
*/
crate.binding.atom_binding = (function (atm,value_func){
this.atm = atm;
this.value_func = value_func;
})
crate.binding.atom_binding.cljs$lang$type = true;
crate.binding.atom_binding.cljs$lang$ctorStr = "crate.binding/atom-binding";
crate.binding.atom_binding.cljs$lang$ctorPrWriter = (function (this__4082__auto__,writer__4083__auto__,opt__4084__auto__){return cljs.core._write.call(null,writer__4083__auto__,"crate.binding/atom-binding");
});
crate.binding.atom_binding.prototype.crate$binding$bindable$ = true;
crate.binding.atom_binding.prototype.crate$binding$bindable$_value$arity$1 = (function (this$){var self__ = this;
var this$__$1 = this;return self__.value_func.call(null,cljs.core.deref.call(null,self__.atm));
});
crate.binding.atom_binding.prototype.crate$binding$bindable$_on_change$arity$2 = (function (this$,func){var self__ = this;
var this$__$1 = this;return cljs.core.add_watch.call(null,self__.atm,cljs.core.gensym.call(null,"atom-binding"),(function (){return func.call(null,crate.binding._value.call(null,this$__$1));
}));
});
crate.binding.__GT_atom_binding = (function __GT_atom_binding(atm,value_func){return (new crate.binding.atom_binding(atm,value_func));
});

/**
* @constructor
*/
crate.binding.notifier = (function (watches){
this.watches = watches;
this.cljs$lang$protocol_mask$partition0$ = 0;
this.cljs$lang$protocol_mask$partition1$ = 2;
})
crate.binding.notifier.cljs$lang$type = true;
crate.binding.notifier.cljs$lang$ctorStr = "crate.binding/notifier";
crate.binding.notifier.cljs$lang$ctorPrWriter = (function (this__4082__auto__,writer__4083__auto__,opt__4084__auto__){return cljs.core._write.call(null,writer__4083__auto__,"crate.binding/notifier");
});
crate.binding.notifier.prototype.cljs$core$IWatchable$_notify_watches$arity$3 = (function (this$,oldval,newval){var self__ = this;
var this$__$1 = this;var seq__15831 = cljs.core.seq.call(null,self__.watches);var chunk__15832 = null;var count__15833 = 0;var i__15834 = 0;while(true){
if((i__15834 < count__15833))
{var vec__15835 = cljs.core._nth.call(null,chunk__15832,i__15834);var key = cljs.core.nth.call(null,vec__15835,0,null);var f = cljs.core.nth.call(null,vec__15835,1,null);f.call(null,key,this$__$1,oldval,newval);
{
var G__15837 = seq__15831;
var G__15838 = chunk__15832;
var G__15839 = count__15833;
var G__15840 = (i__15834 + 1);
seq__15831 = G__15837;
chunk__15832 = G__15838;
count__15833 = G__15839;
i__15834 = G__15840;
continue;
}
} else
{var temp__4092__auto__ = cljs.core.seq.call(null,seq__15831);if(temp__4092__auto__)
{var seq__15831__$1 = temp__4092__auto__;if(cljs.core.chunked_seq_QMARK_.call(null,seq__15831__$1))
{var c__4262__auto__ = cljs.core.chunk_first.call(null,seq__15831__$1);{
var G__15841 = cljs.core.chunk_rest.call(null,seq__15831__$1);
var G__15842 = c__4262__auto__;
var G__15843 = cljs.core.count.call(null,c__4262__auto__);
var G__15844 = 0;
seq__15831 = G__15841;
chunk__15832 = G__15842;
count__15833 = G__15843;
i__15834 = G__15844;
continue;
}
} else
{var vec__15836 = cljs.core.first.call(null,seq__15831__$1);var key = cljs.core.nth.call(null,vec__15836,0,null);var f = cljs.core.nth.call(null,vec__15836,1,null);f.call(null,key,this$__$1,oldval,newval);
{
var G__15845 = cljs.core.next.call(null,seq__15831__$1);
var G__15846 = null;
var G__15847 = 0;
var G__15848 = 0;
seq__15831 = G__15845;
chunk__15832 = G__15846;
count__15833 = G__15847;
i__15834 = G__15848;
continue;
}
}
} else
{return null;
}
}
break;
}
});
crate.binding.notifier.prototype.cljs$core$IWatchable$_add_watch$arity$3 = (function (this$,key,f){var self__ = this;
var this$__$1 = this;return this$__$1.watches = cljs.core.assoc.call(null,self__.watches,key,f);
});
crate.binding.notifier.prototype.cljs$core$IWatchable$_remove_watch$arity$2 = (function (this$,key){var self__ = this;
var this$__$1 = this;return this$__$1.watches = cljs.core.dissoc.call(null,self__.watches,key);
});
crate.binding.__GT_notifier = (function __GT_notifier(watches){return (new crate.binding.notifier(watches));
});

/**
* @constructor
*/
crate.binding.bound_collection = (function (atm,notif,opts,stuff){
this.atm = atm;
this.notif = notif;
this.opts = opts;
this.stuff = stuff;
})
crate.binding.bound_collection.cljs$lang$type = true;
crate.binding.bound_collection.cljs$lang$ctorStr = "crate.binding/bound-collection";
crate.binding.bound_collection.cljs$lang$ctorPrWriter = (function (this__4082__auto__,writer__4083__auto__,opt__4084__auto__){return cljs.core._write.call(null,writer__4083__auto__,"crate.binding/bound-collection");
});
crate.binding.bound_collection.prototype.crate$binding$bindable$ = true;
crate.binding.bound_collection.prototype.crate$binding$bindable$_value$arity$1 = (function (this$){var self__ = this;
var this$__$1 = this;return cljs.core.map.call(null,new cljs.core.Keyword(null,"elem","elem",1017020161),cljs.core.vals.call(null,this$__$1.stuff));
});
crate.binding.bound_collection.prototype.crate$binding$bindable$_on_change$arity$2 = (function (this$,func){var self__ = this;
var this$__$1 = this;return cljs.core.add_watch.call(null,self__.notif,cljs.core.gensym.call(null,"bound-coll"),(function (_,___$1,___$2,p__15849){var vec__15850 = p__15849;var event = cljs.core.nth.call(null,vec__15850,0,null);var el = cljs.core.nth.call(null,vec__15850,1,null);var v = cljs.core.nth.call(null,vec__15850,2,null);return func.call(null,event,el,v);
}));
});
crate.binding.bound_collection.prototype.crate$binding$bindable_coll$ = true;
crate.binding.__GT_bound_collection = (function __GT_bound_collection(atm,notif,opts,stuff){return (new crate.binding.bound_collection(atm,notif,opts,stuff));
});
crate.binding.opt = (function opt(bc,k){return bc.opts.call(null,k);
});
crate.binding.bc_add = (function bc_add(bc,path,key){var sa = crate.binding.subatom.call(null,bc.atm,path);var elem = crate.binding.opt.call(null,bc,new cljs.core.Keyword(null,"as","as",1013907364)).call(null,sa);bc.stuff = cljs.core.assoc.call(null,bc.stuff,key,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"elem","elem",1017020161),elem,new cljs.core.Keyword(null,"subatom","subatom",3440732931),sa], null));
return crate.binding.notify.call(null,bc.notif,null,new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"add","add",1014000659),elem,cljs.core.deref.call(null,sa)], null));
});
crate.binding.bc_remove = (function bc_remove(bc,key){var notif = bc.notif;var prev = bc.stuff.call(null,key);bc.stuff = cljs.core.dissoc.call(null,bc.stuff,key);
crate.binding.notify.call(null,bc.notif,null,new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"remove","remove",4374260726),new cljs.core.Keyword(null,"elem","elem",1017020161).cljs$core$IFn$_invoke$arity$1(prev),null], null));
return crate.binding.sub_destroy_BANG_.call(null,new cljs.core.Keyword(null,"subatom","subatom",3440732931).cljs$core$IFn$_invoke$arity$1(prev));
});
crate.binding.__GT_indexed = (function __GT_indexed(coll){if(cljs.core.map_QMARK_.call(null,coll))
{return cljs.core.seq.call(null,coll);
} else
{if(cljs.core.set_QMARK_.call(null,coll))
{return cljs.core.map.call(null,cljs.core.juxt.call(null,cljs.core.identity,cljs.core.identity),coll);
} else
{if(new cljs.core.Keyword(null,"else","else",1017020587))
{return cljs.core.map_indexed.call(null,cljs.core.vector,coll);
} else
{return null;
}
}
}
});
crate.binding.__GT_keyed = (function __GT_keyed(coll,keyfn){return cljs.core.into.call(null,cljs.core.PersistentHashSet.EMPTY,cljs.core.map.call(null,keyfn,crate.binding.__GT_indexed.call(null,coll)));
});
/**
* @param {...*} var_args
*/
crate.binding.__GT_path = (function() { 
var __GT_path__delegate = function (bc,segs){return cljs.core.concat.call(null,(function (){var or__3520__auto__ = crate.binding.opt.call(null,bc,new cljs.core.Keyword(null,"path","path",1017337751));if(cljs.core.truth_(or__3520__auto__))
{return or__3520__auto__;
} else
{return cljs.core.PersistentVector.EMPTY;
}
})(),segs);
};
var __GT_path = function (bc,var_args){
var segs = null;if (arguments.length > 1) {
  segs = cljs.core.array_seq(Array.prototype.slice.call(arguments, 1),0);} 
return __GT_path__delegate.call(this,bc,segs);};
__GT_path.cljs$lang$maxFixedArity = 1;
__GT_path.cljs$lang$applyTo = (function (arglist__15851){
var bc = cljs.core.first(arglist__15851);
var segs = cljs.core.rest(arglist__15851);
return __GT_path__delegate(bc,segs);
});
__GT_path.cljs$core$IFn$_invoke$arity$variadic = __GT_path__delegate;
return __GT_path;
})()
;
crate.binding.bc_compare = (function bc_compare(bc,neue){var prev = bc.stuff;var pset = cljs.core.into.call(null,cljs.core.PersistentHashSet.EMPTY,cljs.core.keys.call(null,prev));var nset = crate.binding.__GT_keyed.call(null,neue,crate.binding.opt.call(null,bc,new cljs.core.Keyword(null,"keyfn","keyfn",1115849433)));var added = cljs.core.into.call(null,cljs.core.sorted_set.call(null),clojure.set.difference.call(null,nset,pset));var removed = cljs.core.into.call(null,cljs.core.sorted_set.call(null),clojure.set.difference.call(null,pset,nset));var seq__15860_15868 = cljs.core.seq.call(null,added);var chunk__15861_15869 = null;var count__15862_15870 = 0;var i__15863_15871 = 0;while(true){
if((i__15863_15871 < count__15862_15870))
{var a_15872 = cljs.core._nth.call(null,chunk__15861_15869,i__15863_15871);crate.binding.bc_add.call(null,bc,a_15872,a_15872);
{
var G__15873 = seq__15860_15868;
var G__15874 = chunk__15861_15869;
var G__15875 = count__15862_15870;
var G__15876 = (i__15863_15871 + 1);
seq__15860_15868 = G__15873;
chunk__15861_15869 = G__15874;
count__15862_15870 = G__15875;
i__15863_15871 = G__15876;
continue;
}
} else
{var temp__4092__auto___15877 = cljs.core.seq.call(null,seq__15860_15868);if(temp__4092__auto___15877)
{var seq__15860_15878__$1 = temp__4092__auto___15877;if(cljs.core.chunked_seq_QMARK_.call(null,seq__15860_15878__$1))
{var c__4262__auto___15879 = cljs.core.chunk_first.call(null,seq__15860_15878__$1);{
var G__15880 = cljs.core.chunk_rest.call(null,seq__15860_15878__$1);
var G__15881 = c__4262__auto___15879;
var G__15882 = cljs.core.count.call(null,c__4262__auto___15879);
var G__15883 = 0;
seq__15860_15868 = G__15880;
chunk__15861_15869 = G__15881;
count__15862_15870 = G__15882;
i__15863_15871 = G__15883;
continue;
}
} else
{var a_15884 = cljs.core.first.call(null,seq__15860_15878__$1);crate.binding.bc_add.call(null,bc,a_15884,a_15884);
{
var G__15885 = cljs.core.next.call(null,seq__15860_15878__$1);
var G__15886 = null;
var G__15887 = 0;
var G__15888 = 0;
seq__15860_15868 = G__15885;
chunk__15861_15869 = G__15886;
count__15862_15870 = G__15887;
i__15863_15871 = G__15888;
continue;
}
}
} else
{}
}
break;
}
var seq__15864 = cljs.core.seq.call(null,removed);var chunk__15865 = null;var count__15866 = 0;var i__15867 = 0;while(true){
if((i__15867 < count__15866))
{var r = cljs.core._nth.call(null,chunk__15865,i__15867);crate.binding.bc_remove.call(null,bc,r);
{
var G__15889 = seq__15864;
var G__15890 = chunk__15865;
var G__15891 = count__15866;
var G__15892 = (i__15867 + 1);
seq__15864 = G__15889;
chunk__15865 = G__15890;
count__15866 = G__15891;
i__15867 = G__15892;
continue;
}
} else
{var temp__4092__auto__ = cljs.core.seq.call(null,seq__15864);if(temp__4092__auto__)
{var seq__15864__$1 = temp__4092__auto__;if(cljs.core.chunked_seq_QMARK_.call(null,seq__15864__$1))
{var c__4262__auto__ = cljs.core.chunk_first.call(null,seq__15864__$1);{
var G__15893 = cljs.core.chunk_rest.call(null,seq__15864__$1);
var G__15894 = c__4262__auto__;
var G__15895 = cljs.core.count.call(null,c__4262__auto__);
var G__15896 = 0;
seq__15864 = G__15893;
chunk__15865 = G__15894;
count__15866 = G__15895;
i__15867 = G__15896;
continue;
}
} else
{var r = cljs.core.first.call(null,seq__15864__$1);crate.binding.bc_remove.call(null,bc,r);
{
var G__15897 = cljs.core.next.call(null,seq__15864__$1);
var G__15898 = null;
var G__15899 = 0;
var G__15900 = 0;
seq__15864 = G__15897;
chunk__15865 = G__15898;
count__15866 = G__15899;
i__15867 = G__15900;
continue;
}
}
} else
{return null;
}
}
break;
}
});
/**
* @param {...*} var_args
*/
crate.binding.bound_coll = (function() { 
var bound_coll__delegate = function (atm,p__15901){var vec__15904 = p__15901;var path = cljs.core.nth.call(null,vec__15904,0,null);var opts = cljs.core.nth.call(null,vec__15904,1,null);var vec__15905 = (cljs.core.truth_(opts)?new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [path,opts], null):new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [null,path], null));var path__$1 = cljs.core.nth.call(null,vec__15905,0,null);var opts__$1 = cljs.core.nth.call(null,vec__15905,1,null);var atm__$1 = ((cljs.core.not.call(null,path__$1))?atm:crate.binding.subatom.call(null,atm,path__$1));var opts__$2 = cljs.core.assoc.call(null,opts__$1,new cljs.core.Keyword(null,"path","path",1017337751),path__$1);var opts__$3 = ((cljs.core.not.call(null,new cljs.core.Keyword(null,"keyfn","keyfn",1115849433).cljs$core$IFn$_invoke$arity$1(opts__$2)))?cljs.core.assoc.call(null,opts__$2,new cljs.core.Keyword(null,"keyfn","keyfn",1115849433),cljs.core.first):cljs.core.assoc.call(null,opts__$2,new cljs.core.Keyword(null,"keyfn","keyfn",1115849433),cljs.core.comp.call(null,new cljs.core.Keyword(null,"keyfn","keyfn",1115849433).cljs$core$IFn$_invoke$arity$1(opts__$2),cljs.core.second)));var bc = (new crate.binding.bound_collection(atm__$1,(new crate.binding.notifier(null)),opts__$3,cljs.core.sorted_map.call(null)));cljs.core.add_watch.call(null,atm__$1,cljs.core.gensym.call(null,"bound-coll"),(function (_,___$1,___$2,neue){return crate.binding.bc_compare.call(null,bc,neue);
}));
crate.binding.bc_compare.call(null,bc,cljs.core.deref.call(null,atm__$1));
return bc;
};
var bound_coll = function (atm,var_args){
var p__15901 = null;if (arguments.length > 1) {
  p__15901 = cljs.core.array_seq(Array.prototype.slice.call(arguments, 1),0);} 
return bound_coll__delegate.call(this,atm,p__15901);};
bound_coll.cljs$lang$maxFixedArity = 1;
bound_coll.cljs$lang$applyTo = (function (arglist__15906){
var atm = cljs.core.first(arglist__15906);
var p__15901 = cljs.core.rest(arglist__15906);
return bound_coll__delegate(atm,p__15901);
});
bound_coll.cljs$core$IFn$_invoke$arity$variadic = bound_coll__delegate;
return bound_coll;
})()
;
/**
* @param {...*} var_args
*/
crate.binding.map_bound = (function() { 
var map_bound__delegate = function (as,atm,p__15907){var vec__15909 = p__15907;var opts = cljs.core.nth.call(null,vec__15909,0,null);var opts__$1 = cljs.core.assoc.call(null,opts,new cljs.core.Keyword(null,"as","as",1013907364),as);var atm__$1 = ((cljs.core.not.call(null,new cljs.core.Keyword(null,"path","path",1017337751).cljs$core$IFn$_invoke$arity$1(opts__$1)))?atm:crate.binding.subatom.call(null,atm,new cljs.core.Keyword(null,"path","path",1017337751).cljs$core$IFn$_invoke$arity$1(opts__$1)));var opts__$2 = ((cljs.core.not.call(null,new cljs.core.Keyword(null,"keyfn","keyfn",1115849433).cljs$core$IFn$_invoke$arity$1(opts__$1)))?cljs.core.assoc.call(null,opts__$1,new cljs.core.Keyword(null,"keyfn","keyfn",1115849433),cljs.core.first):cljs.core.assoc.call(null,opts__$1,new cljs.core.Keyword(null,"keyfn","keyfn",1115849433),cljs.core.comp.call(null,new cljs.core.Keyword(null,"keyfn","keyfn",1115849433).cljs$core$IFn$_invoke$arity$1(opts__$1),cljs.core.second)));var bc = (new crate.binding.bound_collection(atm__$1,(new crate.binding.notifier(null)),opts__$2,cljs.core.sorted_map.call(null)));cljs.core.add_watch.call(null,atm__$1,cljs.core.gensym.call(null,"bound-coll"),(function (_,___$1,___$2,neue){return crate.binding.bc_compare.call(null,bc,neue);
}));
crate.binding.bc_compare.call(null,bc,cljs.core.deref.call(null,atm__$1));
return bc;
};
var map_bound = function (as,atm,var_args){
var p__15907 = null;if (arguments.length > 2) {
  p__15907 = cljs.core.array_seq(Array.prototype.slice.call(arguments, 2),0);} 
return map_bound__delegate.call(this,as,atm,p__15907);};
map_bound.cljs$lang$maxFixedArity = 2;
map_bound.cljs$lang$applyTo = (function (arglist__15910){
var as = cljs.core.first(arglist__15910);
arglist__15910 = cljs.core.next(arglist__15910);
var atm = cljs.core.first(arglist__15910);
var p__15907 = cljs.core.rest(arglist__15910);
return map_bound__delegate(as,atm,p__15907);
});
map_bound.cljs$core$IFn$_invoke$arity$variadic = map_bound__delegate;
return map_bound;
})()
;
crate.binding.binding_QMARK_ = (function binding_QMARK_(b){var G__15912 = b;if(G__15912)
{var bit__4164__auto__ = null;if(cljs.core.truth_((function (){var or__3520__auto__ = bit__4164__auto__;if(cljs.core.truth_(or__3520__auto__))
{return or__3520__auto__;
} else
{return G__15912.crate$binding$bindable$;
}
})()))
{return true;
} else
{if((!G__15912.cljs$lang$protocol_mask$partition$))
{return cljs.core.native_satisfies_QMARK_.call(null,crate.binding.bindable,G__15912);
} else
{return false;
}
}
} else
{return cljs.core.native_satisfies_QMARK_.call(null,crate.binding.bindable,G__15912);
}
});
crate.binding.binding_coll_QMARK_ = (function binding_coll_QMARK_(b){var G__15914 = b;if(G__15914)
{var bit__4164__auto__ = null;if(cljs.core.truth_((function (){var or__3520__auto__ = bit__4164__auto__;if(cljs.core.truth_(or__3520__auto__))
{return or__3520__auto__;
} else
{return G__15914.crate$binding$bindable_coll$;
}
})()))
{return true;
} else
{if((!G__15914.cljs$lang$protocol_mask$partition$))
{return cljs.core.native_satisfies_QMARK_.call(null,crate.binding.bindable_coll,G__15914);
} else
{return false;
}
}
} else
{return cljs.core.native_satisfies_QMARK_.call(null,crate.binding.bindable_coll,G__15914);
}
});
crate.binding.deref_QMARK_ = (function deref_QMARK_(atm){var G__15916 = atm;if(G__15916)
{var bit__4164__auto__ = (G__15916.cljs$lang$protocol_mask$partition0$ & 32768);if((bit__4164__auto__) || (G__15916.cljs$core$IDeref$))
{return true;
} else
{if((!G__15916.cljs$lang$protocol_mask$partition0$))
{return cljs.core.native_satisfies_QMARK_.call(null,cljs.core.IDeref,G__15916);
} else
{return false;
}
}
} else
{return cljs.core.native_satisfies_QMARK_.call(null,cljs.core.IDeref,G__15916);
}
});
crate.binding.value = (function value(b){return crate.binding._value.call(null,b);
});
crate.binding.index = (function index(sub_atom){return cljs.core.last.call(null,sub_atom.path);
});
crate.binding.on_change = (function on_change(b,func){return crate.binding._on_change.call(null,b,func);
});
/**
* @param {...*} var_args
*/
crate.binding.bound = (function() { 
var bound__delegate = function (atm,p__15917){var vec__15919 = p__15917;var func = cljs.core.nth.call(null,vec__15919,0,null);var func__$1 = (function (){var or__3520__auto__ = func;if(cljs.core.truth_(or__3520__auto__))
{return or__3520__auto__;
} else
{return cljs.core.identity;
}
})();return (new crate.binding.atom_binding(atm,func__$1));
};
var bound = function (atm,var_args){
var p__15917 = null;if (arguments.length > 1) {
  p__15917 = cljs.core.array_seq(Array.prototype.slice.call(arguments, 1),0);} 
return bound__delegate.call(this,atm,p__15917);};
bound.cljs$lang$maxFixedArity = 1;
bound.cljs$lang$applyTo = (function (arglist__15920){
var atm = cljs.core.first(arglist__15920);
var p__15917 = cljs.core.rest(arglist__15920);
return bound__delegate(atm,p__15917);
});
bound.cljs$core$IFn$_invoke$arity$variadic = bound__delegate;
return bound;
})()
;
