// Compiled by ClojureScript 1.10.520 {}
goog.provide('hoplon.storage_atom');
goog.require('cljs.core');
goog.require('cljs.reader');

/**
 * Represents a storage resource.
 * @interface
 */
hoplon.storage_atom.IStorageBackend = function(){};

hoplon.storage_atom._get = (function hoplon$storage_atom$_get(this$,not_found){
if((((!((this$ == null)))) && ((!((this$.hoplon$storage_atom$IStorageBackend$_get$arity$2 == null)))))){
return this$.hoplon$storage_atom$IStorageBackend$_get$arity$2(this$,not_found);
} else {
var x__4433__auto__ = (((this$ == null))?null:this$);
var m__4434__auto__ = (hoplon.storage_atom._get[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,this$,not_found);
} else {
var m__4431__auto__ = (hoplon.storage_atom._get["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.call(null,this$,not_found);
} else {
throw cljs.core.missing_protocol.call(null,"IStorageBackend.-get",this$);
}
}
}
});

/**
 * Commit value to storage at location.
 */
hoplon.storage_atom._commit_BANG_ = (function hoplon$storage_atom$_commit_BANG_(this$,value){
if((((!((this$ == null)))) && ((!((this$.hoplon$storage_atom$IStorageBackend$_commit_BANG_$arity$2 == null)))))){
return this$.hoplon$storage_atom$IStorageBackend$_commit_BANG_$arity$2(this$,value);
} else {
var x__4433__auto__ = (((this$ == null))?null:this$);
var m__4434__auto__ = (hoplon.storage_atom._commit_BANG_[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,this$,value);
} else {
var m__4431__auto__ = (hoplon.storage_atom._commit_BANG_["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.call(null,this$,value);
} else {
throw cljs.core.missing_protocol.call(null,"IStorageBackend.-commit!",this$);
}
}
}
});


/**
* @constructor
 * @implements {hoplon.storage_atom.IStorageBackend}
*/
hoplon.storage_atom.StorageBackend = (function (store,key){
this.store = store;
this.key = key;
});
hoplon.storage_atom.StorageBackend.prototype.hoplon$storage_atom$IStorageBackend$ = cljs.core.PROTOCOL_SENTINEL;

hoplon.storage_atom.StorageBackend.prototype.hoplon$storage_atom$IStorageBackend$_get$arity$2 = (function (this$,not_found){
var self__ = this;
var this$__$1 = this;
var temp__5718__auto__ = self__.store.getItem(cljs.core.pr_str.call(null,self__.key));
if(cljs.core.truth_(temp__5718__auto__)){
var existing = temp__5718__auto__;
return cljs.reader.read_string.call(null,existing);
} else {
return not_found;
}
});

hoplon.storage_atom.StorageBackend.prototype.hoplon$storage_atom$IStorageBackend$_commit_BANG_$arity$2 = (function (this$,value){
var self__ = this;
var this$__$1 = this;
return self__.store.setItem(cljs.core.pr_str.call(null,self__.key),cljs.core.pr_str.call(null,value));
});

hoplon.storage_atom.StorageBackend.getBasis = (function (){
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Symbol(null,"store","store",-1142205747,null),new cljs.core.Symbol(null,"key","key",124488940,null)], null);
});

hoplon.storage_atom.StorageBackend.cljs$lang$type = true;

hoplon.storage_atom.StorageBackend.cljs$lang$ctorStr = "hoplon.storage-atom/StorageBackend";

hoplon.storage_atom.StorageBackend.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){
return cljs.core._write.call(null,writer__4375__auto__,"hoplon.storage-atom/StorageBackend");
});

/**
 * Positional factory function for hoplon.storage-atom/StorageBackend.
 */
hoplon.storage_atom.__GT_StorageBackend = (function hoplon$storage_atom$__GT_StorageBackend(store,key){
return (new hoplon.storage_atom.StorageBackend(store,key));
});

hoplon.storage_atom.store = (function hoplon$storage_atom$store(var_args){
var args__4736__auto__ = [];
var len__4730__auto___30953 = arguments.length;
var i__4731__auto___30954 = (0);
while(true){
if((i__4731__auto___30954 < len__4730__auto___30953)){
args__4736__auto__.push((arguments[i__4731__auto___30954]));

var G__30955 = (i__4731__auto___30954 + (1));
i__4731__auto___30954 = G__30955;
continue;
} else {
}
break;
}

var argseq__4737__auto__ = ((((2) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((2)),(0),null)):null);
return hoplon.storage_atom.store.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4737__auto__);
});

hoplon.storage_atom.store.cljs$core$IFn$_invoke$arity$variadic = (function (atom,backend,p__30949){
var map__30950 = p__30949;
var map__30950__$1 = (((((!((map__30950 == null))))?(((((map__30950.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__30950.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__30950):map__30950);
var ignore_existing = cljs.core.get.call(null,map__30950__$1,new cljs.core.Keyword(null,"ignore-existing","ignore-existing",1266811770));
var existing = (function (){var or__4131__auto__ = (function (){var and__4120__auto__ = ignore_existing;
if(cljs.core.truth_(and__4120__auto__)){
return new cljs.core.Keyword("hoplon.storage-atom","none","hoplon.storage-atom/none",-1380531245);
} else {
return and__4120__auto__;
}
})();
if(cljs.core.truth_(or__4131__auto__)){
return or__4131__auto__;
} else {
return hoplon.storage_atom._get.call(null,backend,new cljs.core.Keyword("hoplon.storage-atom","none","hoplon.storage-atom/none",-1380531245));
}
})();
if(cljs.core._EQ_.call(null,new cljs.core.Keyword("hoplon.storage-atom","none","hoplon.storage-atom/none",-1380531245),existing)){
hoplon.storage_atom._commit_BANG_.call(null,backend,cljs.core.deref.call(null,atom));
} else {
cljs.core.reset_BANG_.call(null,atom,existing);
}

var G__30952 = atom;
cljs.core.add_watch.call(null,G__30952,new cljs.core.Keyword("hoplon.storage-atom","storage-watch","hoplon.storage-atom/storage-watch",-690647421),((function (G__30952,existing,map__30950,map__30950__$1,ignore_existing){
return (function (p1__30943_SHARP_,p2__30944_SHARP_,p3__30945_SHARP_,p4__30942_SHARP_){
return hoplon.storage_atom._commit_BANG_.call(null,backend,p4__30942_SHARP_);
});})(G__30952,existing,map__30950,map__30950__$1,ignore_existing))
);

return G__30952;
});

hoplon.storage_atom.store.cljs$lang$maxFixedArity = (2);

/** @this {Function} */
hoplon.storage_atom.store.cljs$lang$applyTo = (function (seq30946){
var G__30947 = cljs.core.first.call(null,seq30946);
var seq30946__$1 = cljs.core.next.call(null,seq30946);
var G__30948 = cljs.core.first.call(null,seq30946__$1);
var seq30946__$2 = cljs.core.next.call(null,seq30946__$1);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__30947,G__30948,seq30946__$2);
});

hoplon.storage_atom.html_storage = (function hoplon$storage_atom$html_storage(var_args){
var args__4736__auto__ = [];
var len__4730__auto___30963 = arguments.length;
var i__4731__auto___30964 = (0);
while(true){
if((i__4731__auto___30964 < len__4730__auto___30963)){
args__4736__auto__.push((arguments[i__4731__auto___30964]));

var G__30965 = (i__4731__auto___30964 + (1));
i__4731__auto___30964 = G__30965;
continue;
} else {
}
break;
}

var argseq__4737__auto__ = ((((3) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((3)),(0),null)):null);
return hoplon.storage_atom.html_storage.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),argseq__4737__auto__);
});

hoplon.storage_atom.html_storage.cljs$core$IFn$_invoke$arity$variadic = (function (atom,storage,k,p__30960){
var map__30961 = p__30960;
var map__30961__$1 = (((((!((map__30961 == null))))?(((((map__30961.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__30961.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__30961):map__30961);
var ignore_existing = cljs.core.get.call(null,map__30961__$1,new cljs.core.Keyword(null,"ignore-existing","ignore-existing",1266811770));
return hoplon.storage_atom.store.call(null,atom,(new hoplon.storage_atom.StorageBackend(storage,k)),new cljs.core.Keyword(null,"ignore-existing","ignore-existing",1266811770),ignore_existing);
});

hoplon.storage_atom.html_storage.cljs$lang$maxFixedArity = (3);

/** @this {Function} */
hoplon.storage_atom.html_storage.cljs$lang$applyTo = (function (seq30956){
var G__30957 = cljs.core.first.call(null,seq30956);
var seq30956__$1 = cljs.core.next.call(null,seq30956);
var G__30958 = cljs.core.first.call(null,seq30956__$1);
var seq30956__$2 = cljs.core.next.call(null,seq30956__$1);
var G__30959 = cljs.core.first.call(null,seq30956__$2);
var seq30956__$3 = cljs.core.next.call(null,seq30956__$2);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__30957,G__30958,G__30959,seq30956__$3);
});

hoplon.storage_atom.local_storage = (function hoplon$storage_atom$local_storage(var_args){
var args__4736__auto__ = [];
var len__4730__auto___30972 = arguments.length;
var i__4731__auto___30973 = (0);
while(true){
if((i__4731__auto___30973 < len__4730__auto___30972)){
args__4736__auto__.push((arguments[i__4731__auto___30973]));

var G__30974 = (i__4731__auto___30973 + (1));
i__4731__auto___30973 = G__30974;
continue;
} else {
}
break;
}

var argseq__4737__auto__ = ((((2) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((2)),(0),null)):null);
return hoplon.storage_atom.local_storage.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4737__auto__);
});

hoplon.storage_atom.local_storage.cljs$core$IFn$_invoke$arity$variadic = (function (atom,k,p__30969){
var map__30970 = p__30969;
var map__30970__$1 = (((((!((map__30970 == null))))?(((((map__30970.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__30970.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__30970):map__30970);
var ignore_existing = cljs.core.get.call(null,map__30970__$1,new cljs.core.Keyword(null,"ignore-existing","ignore-existing",1266811770));
return hoplon.storage_atom.html_storage.call(null,atom,localStorage,k,new cljs.core.Keyword(null,"ignore-existing","ignore-existing",1266811770),ignore_existing);
});

hoplon.storage_atom.local_storage.cljs$lang$maxFixedArity = (2);

/** @this {Function} */
hoplon.storage_atom.local_storage.cljs$lang$applyTo = (function (seq30966){
var G__30967 = cljs.core.first.call(null,seq30966);
var seq30966__$1 = cljs.core.next.call(null,seq30966);
var G__30968 = cljs.core.first.call(null,seq30966__$1);
var seq30966__$2 = cljs.core.next.call(null,seq30966__$1);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__30967,G__30968,seq30966__$2);
});

hoplon.storage_atom.session_storage = (function hoplon$storage_atom$session_storage(var_args){
var args__4736__auto__ = [];
var len__4730__auto___30981 = arguments.length;
var i__4731__auto___30982 = (0);
while(true){
if((i__4731__auto___30982 < len__4730__auto___30981)){
args__4736__auto__.push((arguments[i__4731__auto___30982]));

var G__30983 = (i__4731__auto___30982 + (1));
i__4731__auto___30982 = G__30983;
continue;
} else {
}
break;
}

var argseq__4737__auto__ = ((((2) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((2)),(0),null)):null);
return hoplon.storage_atom.session_storage.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4737__auto__);
});

hoplon.storage_atom.session_storage.cljs$core$IFn$_invoke$arity$variadic = (function (atom,k,p__30978){
var map__30979 = p__30978;
var map__30979__$1 = (((((!((map__30979 == null))))?(((((map__30979.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__30979.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__30979):map__30979);
var ignore_existing = cljs.core.get.call(null,map__30979__$1,new cljs.core.Keyword(null,"ignore-existing","ignore-existing",1266811770));
return hoplon.storage_atom.html_storage.call(null,atom,sessionStorage,k,new cljs.core.Keyword(null,"ignore-existing","ignore-existing",1266811770),ignore_existing);
});

hoplon.storage_atom.session_storage.cljs$lang$maxFixedArity = (2);

/** @this {Function} */
hoplon.storage_atom.session_storage.cljs$lang$applyTo = (function (seq30975){
var G__30976 = cljs.core.first.call(null,seq30975);
var seq30975__$1 = cljs.core.next.call(null,seq30975);
var G__30977 = cljs.core.first.call(null,seq30975__$1);
var seq30975__$2 = cljs.core.next.call(null,seq30975__$1);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__30976,G__30977,seq30975__$2);
});

