goog.provide('emptyhead.idea.crud');
/**
 * Helper function to scaffold an 'empty' idea.
 */
emptyhead.idea.crud.register_idea_BANG_ = (function emptyhead$idea$crud$register_idea_BANG_(ref){
cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$4(emptyhead.idea.state.state,cljs.core.assoc_in,new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [ref,new cljs.core.Keyword(null,"_meta","_meta",937543236),new cljs.core.Keyword(null,"_properties","_properties",-1501471594)], null),cljs.core.PersistentHashSet.EMPTY);

cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$4(emptyhead.idea.state.state,cljs.core.assoc_in,new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [ref,new cljs.core.Keyword(null,"_meta","_meta",937543236),new cljs.core.Keyword(null,"_reference","_reference",-253513596)], null),ref);

return ref;
});
/**
 * Swap data inside `idea` with given `data`.
 *   Returns a reference to `idea`.
 */
emptyhead.idea.crud.swap_idea_BANG_ = (function emptyhead$idea$crud$swap_idea_BANG_(idea,data){
cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$4(emptyhead.idea.state.state,cljs.core.assoc,emptyhead.idea.protocol.reference(idea),cljs.core.merge.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([data,new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"_meta","_meta",937543236),emptyhead.idea.protocol.val_fn(new cljs.core.Keyword(null,"_meta","_meta",937543236),idea)], null)], 0)));

return emptyhead.idea.protocol.reference(idea);
});
/**
 * Merge `data` into state of `idea`.
 *   Returns a reference to `idea`.
 */
emptyhead.idea.crud.extend_idea_BANG_ = (function emptyhead$idea$crud$extend_idea_BANG_(idea,data){
cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$4(emptyhead.idea.state.state,cljs.core.assoc,emptyhead.idea.protocol.reference(idea),emptyhead.idea.protocol.val_fn.cljs$core$IFn$_invoke$arity$variadic(cljs.core.merge,idea,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([data], 0)));

return emptyhead.idea.protocol.reference(idea);
});
/**
 * Evaluate `fun` on `idea` with optional extra `args`, then replace `idea` by the result.
 *   Returns a reference to `idea`.
 */
emptyhead.idea.crud.mutate_idea_BANG_ = (function emptyhead$idea$crud$mutate_idea_BANG_(var_args){
var args__5732__auto__ = [];
var len__5726__auto___19911 = arguments.length;
var i__5727__auto___19912 = (0);
while(true){
if((i__5727__auto___19912 < len__5726__auto___19911)){
args__5732__auto__.push((arguments[i__5727__auto___19912]));

var G__19913 = (i__5727__auto___19912 + (1));
i__5727__auto___19912 = G__19913;
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.crud.mutate_idea_BANG_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__5733__auto__);
});

(emptyhead.idea.crud.mutate_idea_BANG_.cljs$core$IFn$_invoke$arity$variadic = (function (fun,idea,args){
emptyhead.idea.crud.swap_idea_BANG_(idea,emptyhead.idea.protocol.val_fn.cljs$core$IFn$_invoke$arity$variadic(fun,idea,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([args], 0)));

return emptyhead.idea.protocol.reference(idea);
}));

(emptyhead.idea.crud.mutate_idea_BANG_.cljs$lang$maxFixedArity = (2));

/** @this {Function} */
(emptyhead.idea.crud.mutate_idea_BANG_.cljs$lang$applyTo = (function (seq19901){
var G__19902 = cljs.core.first(seq19901);
var seq19901__$1 = cljs.core.next(seq19901);
var G__19903 = cljs.core.first(seq19901__$1);
var seq19901__$2 = cljs.core.next(seq19901__$1);
var self__5711__auto__ = this;
return self__5711__auto__.cljs$core$IFn$_invoke$arity$variadic(G__19902,G__19903,seq19901__$2);
}));

/**
 * Delete `idea` from the state.
 *   Returns a copy of the `idea`.
 */
emptyhead.idea.crud.forget_idea_BANG_ = (function emptyhead$idea$crud$forget_idea_BANG_(idea){
var val = emptyhead.idea.protocol.value(idea);
cljs.core.apply.cljs$core$IFn$_invoke$arity$3(emptyhead.idea.property.remove_property_BANG_,idea,emptyhead.idea.property.properties(idea));

emptyhead.idea.protocol.ref_fn((function (p1__19904_SHARP_){
return cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$3(emptyhead.idea.state.state,cljs.core.dissoc,p1__19904_SHARP_);
}),idea);

return emptyhead.idea.protocol.copy(val);
});
/**
 * Instantiate up to `count` new ideas, optionally prefixing reference symbol with `prefix`.
 *   Additionally allows you to immediately attach `properties` and `data`.
 *   Returns a single idea or a list of ideas depending on whether `count` was given.
 */
emptyhead.idea.crud.have_idea_BANG_ = (function emptyhead$idea$crud$have_idea_BANG_(var_args){
var args__5732__auto__ = [];
var len__5726__auto___19914 = arguments.length;
var i__5727__auto___19915 = (0);
while(true){
if((i__5727__auto___19915 < len__5726__auto___19914)){
args__5732__auto__.push((arguments[i__5727__auto___19915]));

var G__19916 = (i__5727__auto___19915 + (1));
i__5727__auto___19915 = G__19916;
continue;
} else {
}
break;
}

var argseq__5733__auto__ = ((((0) < args__5732__auto__.length))?(new cljs.core.IndexedSeq(args__5732__auto__.slice((0)),(0),null)):null);
return emptyhead.idea.crud.have_idea_BANG_.cljs$core$IFn$_invoke$arity$variadic(argseq__5733__auto__);
});

(emptyhead.idea.crud.have_idea_BANG_.cljs$core$IFn$_invoke$arity$variadic = (function (p__19909){
var map__19910 = p__19909;
var map__19910__$1 = cljs.core.__destructure_map(map__19910);
var prefix = cljs.core.get.cljs$core$IFn$_invoke$arity$3(map__19910__$1,new cljs.core.Keyword(null,"prefix","prefix",-265908465),"idea");
var count = cljs.core.get.cljs$core$IFn$_invoke$arity$3(map__19910__$1,new cljs.core.Keyword(null,"count","count",2139924085),(1));
var properties = cljs.core.get.cljs$core$IFn$_invoke$arity$3(map__19910__$1,new cljs.core.Keyword(null,"properties","properties",685819552),cljs.core.PersistentVector.EMPTY);
var data = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__19910__$1,new cljs.core.Keyword(null,"data","data",-232669377));
var shadowing = cljs.core.get.cljs$core$IFn$_invoke$arity$3(map__19910__$1,new cljs.core.Keyword(null,"shadowing","shadowing",617250042),cljs.core.PersistentVector.EMPTY);
var fun = (function (){
return emptyhead.idea.crud.register_idea_BANG_(cljs.core.gensym.cljs$core$IFn$_invoke$arity$1([cljs.core.str.cljs$core$IFn$_invoke$arity$1(prefix),"$"].join('')));
});
var ideas = cljs.core.take.cljs$core$IFn$_invoke$arity$2(count,cljs.core.repeatedly.cljs$core$IFn$_invoke$arity$1(fun));
var shadowing__$1 = cljs.core.apply.cljs$core$IFn$_invoke$arity$2(clojure.set.union,cljs.core.map.cljs$core$IFn$_invoke$arity$2(emptyhead.idea.property.with_property,shadowing));
cljs.core.run_BANG_(emptyhead.idea.crud.forget_idea_BANG_,shadowing__$1);

cljs.core.run_BANG_((function (p1__19905_SHARP_){
return cljs.core.apply.cljs$core$IFn$_invoke$arity$3(emptyhead.idea.property.register_property_BANG_,p1__19905_SHARP_,properties);
}),ideas);

cljs.core.run_BANG_((function (p1__19906_SHARP_){
return emptyhead.idea.property.register_property_BANG_.cljs$core$IFn$_invoke$arity$variadic(p1__19906_SHARP_,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([emptyhead.idea.memtag.uid_of(p1__19906_SHARP_)], 0));
}),ideas);

if(cljs.core.truth_(data)){
cljs.core.run_BANG_((function (p1__19907_SHARP_){
return emptyhead.idea.crud.extend_idea_BANG_(p1__19907_SHARP_,data);
}),ideas);
} else {
}

if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(count,(1))){
return cljs.core.first(ideas);
} else {
return ideas;
}
}));

(emptyhead.idea.crud.have_idea_BANG_.cljs$lang$maxFixedArity = (0));

/** @this {Function} */
(emptyhead.idea.crud.have_idea_BANG_.cljs$lang$applyTo = (function (seq19908){
var self__5712__auto__ = this;
return self__5712__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq19908));
}));


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