// 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__24056__auto__ = (((this$ == null))?null:this$);
var m__24057__auto__ = (hoplon.storage_atom._get[goog.typeOf(x__24056__auto__)]);
if(!((m__24057__auto__ == null))){
return m__24057__auto__.call(null,this$,not_found);
} else {
var m__24057__auto____$1 = (hoplon.storage_atom._get["_"]);
if(!((m__24057__auto____$1 == null))){
return m__24057__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__24056__auto__ = (((this$ == null))?null:this$);
var m__24057__auto__ = (hoplon.storage_atom._commit_BANG_[goog.typeOf(x__24056__auto__)]);
if(!((m__24057__auto__ == null))){
return m__24057__auto__.call(null,this$,value);
} else {
var m__24057__auto____$1 = (hoplon.storage_atom._commit_BANG_["_"]);
if(!((m__24057__auto____$1 == null))){
return m__24057__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__23995__auto__,writer__23996__auto__,opt__23997__auto__){
return cljs.core._write.call(null,writer__23996__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__24566__auto__ = [];
var len__24559__auto___35586 = arguments.length;
var i__24560__auto___35587 = (0);
while(true){
if((i__24560__auto___35587 < len__24559__auto___35586)){
args__24566__auto__.push((arguments[i__24560__auto___35587]));

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

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

hoplon.storage_atom.store.cljs$core$IFn$_invoke$arity$variadic = (function (atom,backend,p__35582){
var map__35583 = p__35582;
var map__35583__$1 = ((((!((map__35583 == null)))?((((map__35583.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35583.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35583):map__35583);
var ignore_existing = cljs.core.get.call(null,map__35583__$1,new cljs.core.Keyword(null,"ignore-existing","ignore-existing",1266811770));
var existing = (function (){var or__23338__auto__ = (function (){var and__23326__auto__ = ignore_existing;
if(cljs.core.truth_(and__23326__auto__)){
return new cljs.core.Keyword("hoplon.storage-atom","none","hoplon.storage-atom/none",-1380531245);
} else {
return and__23326__auto__;
}
})();
if(cljs.core.truth_(or__23338__auto__)){
return or__23338__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__35585 = atom;
cljs.core.add_watch.call(null,G__35585,new cljs.core.Keyword("hoplon.storage-atom","storage-watch","hoplon.storage-atom/storage-watch",-690647421),((function (G__35585,existing,map__35583,map__35583__$1,ignore_existing){
return (function (p1__35576_SHARP_,p2__35577_SHARP_,p3__35578_SHARP_,p4__35575_SHARP_){
return hoplon.storage_atom._commit_BANG_.call(null,backend,p4__35575_SHARP_);
});})(G__35585,existing,map__35583,map__35583__$1,ignore_existing))
);

return G__35585;
});

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

hoplon.storage_atom.store.cljs$lang$applyTo = (function (seq35579){
var G__35580 = cljs.core.first.call(null,seq35579);
var seq35579__$1 = cljs.core.next.call(null,seq35579);
var G__35581 = cljs.core.first.call(null,seq35579__$1);
var seq35579__$2 = cljs.core.next.call(null,seq35579__$1);
return hoplon.storage_atom.store.cljs$core$IFn$_invoke$arity$variadic(G__35580,G__35581,seq35579__$2);
});

hoplon.storage_atom.html_storage = (function hoplon$storage_atom$html_storage(var_args){
var args__24566__auto__ = [];
var len__24559__auto___35596 = arguments.length;
var i__24560__auto___35597 = (0);
while(true){
if((i__24560__auto___35597 < len__24559__auto___35596)){
args__24566__auto__.push((arguments[i__24560__auto___35597]));

var G__35598 = (i__24560__auto___35597 + (1));
i__24560__auto___35597 = G__35598;
continue;
} else {
}
break;
}

var argseq__24567__auto__ = ((((3) < args__24566__auto__.length))?(new cljs.core.IndexedSeq(args__24566__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__24567__auto__);
});

hoplon.storage_atom.html_storage.cljs$core$IFn$_invoke$arity$variadic = (function (atom,storage,k,p__35593){
var map__35594 = p__35593;
var map__35594__$1 = ((((!((map__35594 == null)))?((((map__35594.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35594.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35594):map__35594);
var ignore_existing = cljs.core.get.call(null,map__35594__$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 (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);
var G__35592 = cljs.core.first.call(null,seq35589__$2);
var seq35589__$3 = cljs.core.next.call(null,seq35589__$2);
return hoplon.storage_atom.html_storage.cljs$core$IFn$_invoke$arity$variadic(G__35590,G__35591,G__35592,seq35589__$3);
});

hoplon.storage_atom.local_storage = (function hoplon$storage_atom$local_storage(var_args){
var args__24566__auto__ = [];
var len__24559__auto___35605 = arguments.length;
var i__24560__auto___35606 = (0);
while(true){
if((i__24560__auto___35606 < len__24559__auto___35605)){
args__24566__auto__.push((arguments[i__24560__auto___35606]));

var G__35607 = (i__24560__auto___35606 + (1));
i__24560__auto___35606 = G__35607;
continue;
} else {
}
break;
}

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

hoplon.storage_atom.local_storage.cljs$core$IFn$_invoke$arity$variadic = (function (atom,k,p__35602){
var map__35603 = p__35602;
var map__35603__$1 = ((((!((map__35603 == null)))?((((map__35603.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35603.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35603):map__35603);
var ignore_existing = cljs.core.get.call(null,map__35603__$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 (seq35599){
var G__35600 = cljs.core.first.call(null,seq35599);
var seq35599__$1 = cljs.core.next.call(null,seq35599);
var G__35601 = cljs.core.first.call(null,seq35599__$1);
var seq35599__$2 = cljs.core.next.call(null,seq35599__$1);
return hoplon.storage_atom.local_storage.cljs$core$IFn$_invoke$arity$variadic(G__35600,G__35601,seq35599__$2);
});

hoplon.storage_atom.session_storage = (function hoplon$storage_atom$session_storage(var_args){
var args__24566__auto__ = [];
var len__24559__auto___35614 = arguments.length;
var i__24560__auto___35615 = (0);
while(true){
if((i__24560__auto___35615 < len__24559__auto___35614)){
args__24566__auto__.push((arguments[i__24560__auto___35615]));

var G__35616 = (i__24560__auto___35615 + (1));
i__24560__auto___35615 = G__35616;
continue;
} else {
}
break;
}

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

hoplon.storage_atom.session_storage.cljs$core$IFn$_invoke$arity$variadic = (function (atom,k,p__35611){
var map__35612 = p__35611;
var map__35612__$1 = ((((!((map__35612 == null)))?((((map__35612.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35612.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35612):map__35612);
var ignore_existing = cljs.core.get.call(null,map__35612__$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 (seq35608){
var G__35609 = cljs.core.first.call(null,seq35608);
var seq35608__$1 = cljs.core.next.call(null,seq35608);
var G__35610 = cljs.core.first.call(null,seq35608__$1);
var seq35608__$2 = cljs.core.next.call(null,seq35608__$1);
return hoplon.storage_atom.session_storage.cljs$core$IFn$_invoke$arity$variadic(G__35609,G__35610,seq35608__$2);
});

