goog.provide('emptyhead.idea.protocol');
emptyhead.idea.protocol.to_reference = (function emptyhead$idea$protocol$to_reference(val){
var ref = cljs.core.get_in.cljs$core$IFn$_invoke$arity$2(val,new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"_meta","_meta",937543236),new cljs.core.Keyword(null,"_reference","_reference",-253513596)], null));
if(cljs.core.truth_(cljs.core.get_in.cljs$core$IFn$_invoke$arity$2(val,new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"_meta","_meta",937543236),new cljs.core.Keyword(null,"_stale-reference","_stale-reference",748081018)], null)))){
cljs.core.println.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["fucky wucky ",val], 0));

return emptyhead.util.logging.error.cljs$core$IFn$_invoke$arity$variadic(["Attempt to find stale reference `",cljs.core.str.cljs$core$IFn$_invoke$arity$1(ref),"` -- this is a copy."].join(''),cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"value","value",305978217),val,new cljs.core.Keyword(null,"type","type",1174270348),new cljs.core.Keyword(null,"stale-reference","stale-reference",791234536)], null)], 0));
} else {
if((!((ref instanceof cljs.core.Symbol)))){
return emptyhead.util.logging.error.cljs$core$IFn$_invoke$arity$variadic(["Attempt to find invalid reference `",cljs.core.str.cljs$core$IFn$_invoke$arity$1(ref),"` --  invalid idea?"].join(''),cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"value","value",305978217),val,new cljs.core.Keyword(null,"type","type",1174270348),new cljs.core.Keyword(null,"invalid-reference","invalid-reference",450936464)], null)], 0));
} else {
return ref;

}
}
});

/**
 * @interface
 */
emptyhead.idea.protocol.Idea = function(){};

var emptyhead$idea$protocol$Idea$reference$dyn_19867 = (function (idea){
var x__5350__auto__ = (((idea == null))?null:idea);
var m__5351__auto__ = (emptyhead.idea.protocol.reference[goog.typeOf(x__5350__auto__)]);
if((!((m__5351__auto__ == null)))){
return (m__5351__auto__.cljs$core$IFn$_invoke$arity$1 ? m__5351__auto__.cljs$core$IFn$_invoke$arity$1(idea) : m__5351__auto__.call(null, idea));
} else {
var m__5349__auto__ = (emptyhead.idea.protocol.reference["_"]);
if((!((m__5349__auto__ == null)))){
return (m__5349__auto__.cljs$core$IFn$_invoke$arity$1 ? m__5349__auto__.cljs$core$IFn$_invoke$arity$1(idea) : m__5349__auto__.call(null, idea));
} else {
throw cljs.core.missing_protocol("Idea.reference",idea);
}
}
});
/**
 * Reference, i.e. symbol, for `idea`.
 */
emptyhead.idea.protocol.reference = (function emptyhead$idea$protocol$reference(idea){
if((((!((idea == null)))) && ((!((idea.emptyhead$idea$protocol$Idea$reference$arity$1 == null)))))){
return idea.emptyhead$idea$protocol$Idea$reference$arity$1(idea);
} else {
return emptyhead$idea$protocol$Idea$reference$dyn_19867(idea);
}
});

var emptyhead$idea$protocol$Idea$value$dyn_19869 = (function (idea){
var x__5350__auto__ = (((idea == null))?null:idea);
var m__5351__auto__ = (emptyhead.idea.protocol.value[goog.typeOf(x__5350__auto__)]);
if((!((m__5351__auto__ == null)))){
return (m__5351__auto__.cljs$core$IFn$_invoke$arity$1 ? m__5351__auto__.cljs$core$IFn$_invoke$arity$1(idea) : m__5351__auto__.call(null, idea));
} else {
var m__5349__auto__ = (emptyhead.idea.protocol.value["_"]);
if((!((m__5349__auto__ == null)))){
return (m__5349__auto__.cljs$core$IFn$_invoke$arity$1 ? m__5349__auto__.cljs$core$IFn$_invoke$arity$1(idea) : m__5349__auto__.call(null, idea));
} else {
throw cljs.core.missing_protocol("Idea.value",idea);
}
}
});
/**
 * Value, i.e. map, of `idea`.
 */
emptyhead.idea.protocol.value = (function emptyhead$idea$protocol$value(idea){
if((((!((idea == null)))) && ((!((idea.emptyhead$idea$protocol$Idea$value$arity$1 == null)))))){
return idea.emptyhead$idea$protocol$Idea$value$arity$1(idea);
} else {
return emptyhead$idea$protocol$Idea$value$dyn_19869(idea);
}
});

(cljs.core.PersistentHashMap.prototype.emptyhead$idea$protocol$Idea$ = cljs.core.PROTOCOL_SENTINEL);

(cljs.core.PersistentHashMap.prototype.emptyhead$idea$protocol$Idea$reference$arity$1 = (function (idea){
var idea__$1 = this;
return emptyhead.idea.protocol.to_reference(idea__$1);
}));

(cljs.core.PersistentHashMap.prototype.emptyhead$idea$protocol$Idea$value$arity$1 = (function (idea){
var idea__$1 = this;
return idea__$1;
}));

(cljs.core.PersistentArrayMap.prototype.emptyhead$idea$protocol$Idea$ = cljs.core.PROTOCOL_SENTINEL);

(cljs.core.PersistentArrayMap.prototype.emptyhead$idea$protocol$Idea$reference$arity$1 = (function (idea){
var idea__$1 = this;
return emptyhead.idea.protocol.to_reference(idea__$1);
}));

(cljs.core.PersistentArrayMap.prototype.emptyhead$idea$protocol$Idea$value$arity$1 = (function (idea){
var idea__$1 = this;
return idea__$1;
}));

(cljs.core.Symbol.prototype.emptyhead$idea$protocol$Idea$ = cljs.core.PROTOCOL_SENTINEL);

(cljs.core.Symbol.prototype.emptyhead$idea$protocol$Idea$reference$arity$1 = (function (idea){
var idea__$1 = this;
return idea__$1;
}));

(cljs.core.Symbol.prototype.emptyhead$idea$protocol$Idea$value$arity$1 = (function (idea){
var idea__$1 = this;
return cljs.core.get.cljs$core$IFn$_invoke$arity$2(cljs.core.deref(emptyhead.idea.state.state),idea__$1);
}));
/**
 * Make a copy of `idea`.
 *   Returns an object that is identical to the value of `idea`,
 *   but marked as not containing a reference to anything in the state.
 */
emptyhead.idea.protocol.copy = (function emptyhead$idea$protocol$copy(idea){
return cljs.core.assoc_in(emptyhead.idea.protocol.value(idea),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"_meta","_meta",937543236),new cljs.core.Keyword(null,"_stale-reference","_stale-reference",748081018)], null),true);
});
emptyhead.idea.protocol.non_copy = (function emptyhead$idea$protocol$non_copy(idea){
return cljs.core.assoc_in(emptyhead.idea.protocol.value(idea),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"_meta","_meta",937543236),new cljs.core.Keyword(null,"_stale-reference","_stale-reference",748081018)], null),false);
});
/**
 * Takes a copied idea and 'uncopies' it, making its reference active again
 *   and updating what is in the game state.
 */
emptyhead.idea.protocol.uncopy_BANG_ = (function emptyhead$idea$protocol$uncopy_BANG_(copy_obj){
var idea = emptyhead.idea.protocol.non_copy(copy_obj);
cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$4(emptyhead.idea.state.state,cljs.core.assoc,emptyhead.idea.protocol.reference(idea),idea);

return emptyhead.idea.protocol.reference(idea);
});
/**
 * Get the (now stale!) reference of a copied idea.
 */
emptyhead.idea.protocol.force_reference = (function emptyhead$idea$protocol$force_reference(copy_obj){
return emptyhead.idea.protocol.to_reference(emptyhead.idea.protocol.non_copy(copy_obj));
});
/**
 * Execute `fun` on a copy of `idea` with optional additional `args`.
 */
emptyhead.idea.protocol.copy_fn = (function emptyhead$idea$protocol$copy_fn(var_args){
var args__5732__auto__ = [];
var len__5726__auto___19870 = arguments.length;
var i__5727__auto___19872 = (0);
while(true){
if((i__5727__auto___19872 < len__5726__auto___19870)){
args__5732__auto__.push((arguments[i__5727__auto___19872]));

var G__19873 = (i__5727__auto___19872 + (1));
i__5727__auto___19872 = G__19873;
continue;
} else {
}
break;
}

var argseq__5733__auto__ = ((((2) < args__5732__auto__.length))?(new cljs.core.IndexedSeq(args__5732__auto__.slice((2)),(0),null)):null);
return emptyhead.idea.protocol.copy_fn.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__5733__auto__);
});

(emptyhead.idea.protocol.copy_fn.cljs$core$IFn$_invoke$arity$variadic = (function (fun,idea,args){
return cljs.core.apply.cljs$core$IFn$_invoke$arity$3(fun,emptyhead.idea.protocol.copy(idea),args);
}));

(emptyhead.idea.protocol.copy_fn.cljs$lang$maxFixedArity = (2));

/** @this {Function} */
(emptyhead.idea.protocol.copy_fn.cljs$lang$applyTo = (function (seq19855){
var G__19856 = cljs.core.first(seq19855);
var seq19855__$1 = cljs.core.next(seq19855);
var G__19857 = cljs.core.first(seq19855__$1);
var seq19855__$2 = cljs.core.next(seq19855__$1);
var self__5711__auto__ = this;
return self__5711__auto__.cljs$core$IFn$_invoke$arity$variadic(G__19856,G__19857,seq19855__$2);
}));

/**
 * Execute `fun` on the value of `idea` with optional additional `args`.
 */
emptyhead.idea.protocol.val_fn = (function emptyhead$idea$protocol$val_fn(var_args){
var args__5732__auto__ = [];
var len__5726__auto___19876 = arguments.length;
var i__5727__auto___19877 = (0);
while(true){
if((i__5727__auto___19877 < len__5726__auto___19876)){
args__5732__auto__.push((arguments[i__5727__auto___19877]));

var G__19878 = (i__5727__auto___19877 + (1));
i__5727__auto___19877 = G__19878;
continue;
} else {
}
break;
}

var argseq__5733__auto__ = ((((2) < args__5732__auto__.length))?(new cljs.core.IndexedSeq(args__5732__auto__.slice((2)),(0),null)):null);
return emptyhead.idea.protocol.val_fn.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__5733__auto__);
});

(emptyhead.idea.protocol.val_fn.cljs$core$IFn$_invoke$arity$variadic = (function (fun,idea,args){
return cljs.core.apply.cljs$core$IFn$_invoke$arity$3(fun,emptyhead.idea.protocol.value(idea),args);
}));

(emptyhead.idea.protocol.val_fn.cljs$lang$maxFixedArity = (2));

/** @this {Function} */
(emptyhead.idea.protocol.val_fn.cljs$lang$applyTo = (function (seq19858){
var G__19859 = cljs.core.first(seq19858);
var seq19858__$1 = cljs.core.next(seq19858);
var G__19860 = cljs.core.first(seq19858__$1);
var seq19858__$2 = cljs.core.next(seq19858__$1);
var self__5711__auto__ = this;
return self__5711__auto__.cljs$core$IFn$_invoke$arity$variadic(G__19859,G__19860,seq19858__$2);
}));

/**
 * Execute `fun` on a reference to `idea` with optional additional `args`.
 */
emptyhead.idea.protocol.ref_fn = (function emptyhead$idea$protocol$ref_fn(var_args){
var args__5732__auto__ = [];
var len__5726__auto___19879 = arguments.length;
var i__5727__auto___19880 = (0);
while(true){
if((i__5727__auto___19880 < len__5726__auto___19879)){
args__5732__auto__.push((arguments[i__5727__auto___19880]));

var G__19881 = (i__5727__auto___19880 + (1));
i__5727__auto___19880 = G__19881;
continue;
} else {
}
break;
}

var argseq__5733__auto__ = ((((2) < args__5732__auto__.length))?(new cljs.core.IndexedSeq(args__5732__auto__.slice((2)),(0),null)):null);
return emptyhead.idea.protocol.ref_fn.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__5733__auto__);
});

(emptyhead.idea.protocol.ref_fn.cljs$core$IFn$_invoke$arity$variadic = (function (fun,idea,args){
return cljs.core.apply.cljs$core$IFn$_invoke$arity$3(fun,emptyhead.idea.protocol.reference(idea),args);
}));

(emptyhead.idea.protocol.ref_fn.cljs$lang$maxFixedArity = (2));

/** @this {Function} */
(emptyhead.idea.protocol.ref_fn.cljs$lang$applyTo = (function (seq19861){
var G__19862 = cljs.core.first(seq19861);
var seq19861__$1 = cljs.core.next(seq19861);
var G__19863 = cljs.core.first(seq19861__$1);
var seq19861__$2 = cljs.core.next(seq19861__$1);
var self__5711__auto__ = this;
return self__5711__auto__.cljs$core$IFn$_invoke$arity$variadic(G__19862,G__19863,seq19861__$2);
}));

/**
 * Execute `fun` on a reference to `idea` with optional additional `args`.
 *   Unlike [[reference-fn]], this will work on a copy.
 */
emptyhead.idea.protocol.force_reference_fn = (function emptyhead$idea$protocol$force_reference_fn(var_args){
var args__5732__auto__ = [];
var len__5726__auto___19882 = arguments.length;
var i__5727__auto___19883 = (0);
while(true){
if((i__5727__auto___19883 < len__5726__auto___19882)){
args__5732__auto__.push((arguments[i__5727__auto___19883]));

var G__19884 = (i__5727__auto___19883 + (1));
i__5727__auto___19883 = G__19884;
continue;
} else {
}
break;
}

var argseq__5733__auto__ = ((((2) < args__5732__auto__.length))?(new cljs.core.IndexedSeq(args__5732__auto__.slice((2)),(0),null)):null);
return emptyhead.idea.protocol.force_reference_fn.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__5733__auto__);
});

(emptyhead.idea.protocol.force_reference_fn.cljs$core$IFn$_invoke$arity$variadic = (function (fun,idea,args){
return cljs.core.apply.cljs$core$IFn$_invoke$arity$3(fun,emptyhead.idea.protocol.force_reference(idea),args);
}));

(emptyhead.idea.protocol.force_reference_fn.cljs$lang$maxFixedArity = (2));

/** @this {Function} */
(emptyhead.idea.protocol.force_reference_fn.cljs$lang$applyTo = (function (seq19864){
var G__19865 = cljs.core.first(seq19864);
var seq19864__$1 = cljs.core.next(seq19864);
var G__19866 = cljs.core.first(seq19864__$1);
var seq19864__$2 = cljs.core.next(seq19864__$1);
var self__5711__auto__ = this;
return self__5711__auto__.cljs$core$IFn$_invoke$arity$variadic(G__19865,G__19866,seq19864__$2);
}));


//# sourceMappingURL=emptyhead.idea.protocol.js.map
