// Compiled by ClojureScript 1.9.562 {}
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__23866__auto__ = (((this$ == null))?null:this$);
var m__23867__auto__ = (hoplon.storage_atom._get[goog.typeOf(x__23866__auto__)]);
if(!((m__23867__auto__ == null))){
return m__23867__auto__.call(null,this$,not_found);
} else {
var m__23867__auto____$1 = (hoplon.storage_atom._get["_"]);
if(!((m__23867__auto____$1 == null))){
return m__23867__auto____$1.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__23866__auto__ = (((this$ == null))?null:this$);
var m__23867__auto__ = (hoplon.storage_atom._commit_BANG_[goog.typeOf(x__23866__auto__)]);
if(!((m__23867__auto__ == null))){
return m__23867__auto__.call(null,this$,value);
} else {
var m__23867__auto____$1 = (hoplon.storage_atom._commit_BANG_["_"]);
if(!((m__23867__auto____$1 == null))){
return m__23867__auto____$1.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__5276__auto__ = self__.store.getItem(cljs.core.pr_str.call(null,self__.key));
if(cljs.core.truth_(temp__5276__auto__)){
var existing = temp__5276__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__23805__auto__,writer__23806__auto__,opt__23807__auto__){
return cljs.core._write.call(null,writer__23806__auto__,"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__24376__auto__ = [];
var len__24369__auto___35567 = arguments.length;
var i__24370__auto___35568 = (0);
while(true){
if((i__24370__auto___35568 < len__24369__auto___35567)){
args__24376__auto__.push((arguments[i__24370__auto___35568]));

var G__35569 = (i__24370__auto___35568 + (1));
i__24370__auto___35568 = G__35569;
continue;
} else {
}
break;
}

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

hoplon.storage_atom.store.cljs$core$IFn$_invoke$arity$variadic = (function (atom,backend,p__35563){
var map__35564 = p__35563;
var map__35564__$1 = ((((!((map__35564 == null)))?((((map__35564.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35564.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35564):map__35564);
var ignore_existing = cljs.core.get.call(null,map__35564__$1,new cljs.core.Keyword(null,"ignore-existing","ignore-existing",1266811770));
var existing = (function (){var or__23148__auto__ = (function (){var and__23136__auto__ = ignore_existing;
if(cljs.core.truth_(and__23136__auto__)){
return new cljs.core.Keyword("hoplon.storage-atom","none","hoplon.storage-atom/none",-1380531245);
} else {
return and__23136__auto__;
}
})();
if(cljs.core.truth_(or__23148__auto__)){
return or__23148__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__35566 = atom;
cljs.core.add_watch.call(null,G__35566,new cljs.core.Keyword("hoplon.storage-atom","storage-watch","hoplon.storage-atom/storage-watch",-690647421),((function (G__35566,existing,map__35564,map__35564__$1,ignore_existing){
return (function (p1__35557_SHARP_,p2__35558_SHARP_,p3__35559_SHARP_,p4__35556_SHARP_){
return hoplon.storage_atom._commit_BANG_.call(null,backend,p4__35556_SHARP_);
});})(G__35566,existing,map__35564,map__35564__$1,ignore_existing))
);

return G__35566;
});

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

hoplon.storage_atom.store.cljs$lang$applyTo = (function (seq35560){
var G__35561 = cljs.core.first.call(null,seq35560);
var seq35560__$1 = cljs.core.next.call(null,seq35560);
var G__35562 = cljs.core.first.call(null,seq35560__$1);
var seq35560__$2 = cljs.core.next.call(null,seq35560__$1);
return hoplon.storage_atom.store.cljs$core$IFn$_invoke$arity$variadic(G__35561,G__35562,seq35560__$2);
});

hoplon.storage_atom.html_storage = (function hoplon$storage_atom$html_storage(var_args){
var args__24376__auto__ = [];
var len__24369__auto___35577 = arguments.length;
var i__24370__auto___35578 = (0);
while(true){
if((i__24370__auto___35578 < len__24369__auto___35577)){
args__24376__auto__.push((arguments[i__24370__auto___35578]));

var G__35579 = (i__24370__auto___35578 + (1));
i__24370__auto___35578 = G__35579;
continue;
} else {
}
break;
}

var argseq__24377__auto__ = ((((3) < args__24376__auto__.length))?(new cljs.core.IndexedSeq(args__24376__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__24377__auto__);
});

hoplon.storage_atom.html_storage.cljs$core$IFn$_invoke$arity$variadic = (function (atom,storage,k,p__35574){
var map__35575 = p__35574;
var map__35575__$1 = ((((!((map__35575 == null)))?((((map__35575.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35575.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35575):map__35575);
var ignore_existing = cljs.core.get.call(null,map__35575__$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);

hoplon.storage_atom.html_storage.cljs$lang$applyTo = (function (seq35570){
var G__35571 = cljs.core.first.call(null,seq35570);
var seq35570__$1 = cljs.core.next.call(null,seq35570);
var G__35572 = cljs.core.first.call(null,seq35570__$1);
var seq35570__$2 = cljs.core.next.call(null,seq35570__$1);
var G__35573 = cljs.core.first.call(null,seq35570__$2);
var seq35570__$3 = cljs.core.next.call(null,seq35570__$2);
return hoplon.storage_atom.html_storage.cljs$core$IFn$_invoke$arity$variadic(G__35571,G__35572,G__35573,seq35570__$3);
});

hoplon.storage_atom.local_storage = (function hoplon$storage_atom$local_storage(var_args){
var args__24376__auto__ = [];
var len__24369__auto___35586 = arguments.length;
var i__24370__auto___35587 = (0);
while(true){
if((i__24370__auto___35587 < len__24369__auto___35586)){
args__24376__auto__.push((arguments[i__24370__auto___35587]));

var G__35588 = (i__24370__auto___35587 + (1));
i__24370__auto___35587 = G__35588;
continue;
} else {
}
break;
}

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

hoplon.storage_atom.local_storage.cljs$core$IFn$_invoke$arity$variadic = (function (atom,k,p__35583){
var map__35584 = p__35583;
var map__35584__$1 = ((((!((map__35584 == null)))?((((map__35584.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35584.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35584):map__35584);
var ignore_existing = cljs.core.get.call(null,map__35584__$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);

hoplon.storage_atom.local_storage.cljs$lang$applyTo = (function (seq35580){
var G__35581 = cljs.core.first.call(null,seq35580);
var seq35580__$1 = cljs.core.next.call(null,seq35580);
var G__35582 = cljs.core.first.call(null,seq35580__$1);
var seq35580__$2 = cljs.core.next.call(null,seq35580__$1);
return hoplon.storage_atom.local_storage.cljs$core$IFn$_invoke$arity$variadic(G__35581,G__35582,seq35580__$2);
});

hoplon.storage_atom.session_storage = (function hoplon$storage_atom$session_storage(var_args){
var args__24376__auto__ = [];
var len__24369__auto___35595 = arguments.length;
var i__24370__auto___35596 = (0);
while(true){
if((i__24370__auto___35596 < len__24369__auto___35595)){
args__24376__auto__.push((arguments[i__24370__auto___35596]));

var G__35597 = (i__24370__auto___35596 + (1));
i__24370__auto___35596 = G__35597;
continue;
} else {
}
break;
}

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

hoplon.storage_atom.session_storage.cljs$core$IFn$_invoke$arity$variadic = (function (atom,k,p__35592){
var map__35593 = p__35592;
var map__35593__$1 = ((((!((map__35593 == null)))?((((map__35593.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35593.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35593):map__35593);
var ignore_existing = cljs.core.get.call(null,map__35593__$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);

hoplon.storage_atom.session_storage.cljs$lang$applyTo = (function (seq35589){
var G__35590 = cljs.core.first.call(null,seq35589);
var seq35589__$1 = cljs.core.next.call(null,seq35589);
var G__35591 = cljs.core.first.call(null,seq35589__$1);
var seq35589__$2 = cljs.core.next.call(null,seq35589__$1);
return hoplon.storage_atom.session_storage.cljs$core$IFn$_invoke$arity$variadic(G__35590,G__35591,seq35589__$2);
});

