// 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___35486 = arguments.length;
var i__24560__auto___35487 = (0);
while(true){
if((i__24560__auto___35487 < len__24559__auto___35486)){
args__24566__auto__.push((arguments[i__24560__auto___35487]));

var G__35488 = (i__24560__auto___35487 + (1));
i__24560__auto___35487 = G__35488;
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__35482){
var map__35483 = p__35482;
var map__35483__$1 = ((((!((map__35483 == null)))?((((map__35483.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35483.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35483):map__35483);
var ignore_existing = cljs.core.get.call(null,map__35483__$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__35485 = atom;
cljs.core.add_watch.call(null,G__35485,new cljs.core.Keyword("hoplon.storage-atom","storage-watch","hoplon.storage-atom/storage-watch",-690647421),((function (G__35485,existing,map__35483,map__35483__$1,ignore_existing){
return (function (p1__35476_SHARP_,p2__35477_SHARP_,p3__35478_SHARP_,p4__35475_SHARP_){
return hoplon.storage_atom._commit_BANG_.call(null,backend,p4__35475_SHARP_);
});})(G__35485,existing,map__35483,map__35483__$1,ignore_existing))
);

return G__35485;
});

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

hoplon.storage_atom.store.cljs$lang$applyTo = (function (seq35479){
var G__35480 = cljs.core.first.call(null,seq35479);
var seq35479__$1 = cljs.core.next.call(null,seq35479);
var G__35481 = cljs.core.first.call(null,seq35479__$1);
var seq35479__$2 = cljs.core.next.call(null,seq35479__$1);
return hoplon.storage_atom.store.cljs$core$IFn$_invoke$arity$variadic(G__35480,G__35481,seq35479__$2);
});

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

var G__35498 = (i__24560__auto___35497 + (1));
i__24560__auto___35497 = G__35498;
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__35493){
var map__35494 = p__35493;
var map__35494__$1 = ((((!((map__35494 == null)))?((((map__35494.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35494.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35494):map__35494);
var ignore_existing = cljs.core.get.call(null,map__35494__$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 (seq35489){
var G__35490 = cljs.core.first.call(null,seq35489);
var seq35489__$1 = cljs.core.next.call(null,seq35489);
var G__35491 = cljs.core.first.call(null,seq35489__$1);
var seq35489__$2 = cljs.core.next.call(null,seq35489__$1);
var G__35492 = cljs.core.first.call(null,seq35489__$2);
var seq35489__$3 = cljs.core.next.call(null,seq35489__$2);
return hoplon.storage_atom.html_storage.cljs$core$IFn$_invoke$arity$variadic(G__35490,G__35491,G__35492,seq35489__$3);
});

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

var G__35507 = (i__24560__auto___35506 + (1));
i__24560__auto___35506 = G__35507;
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__35502){
var map__35503 = p__35502;
var map__35503__$1 = ((((!((map__35503 == null)))?((((map__35503.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35503.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35503):map__35503);
var ignore_existing = cljs.core.get.call(null,map__35503__$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 (seq35499){
var G__35500 = cljs.core.first.call(null,seq35499);
var seq35499__$1 = cljs.core.next.call(null,seq35499);
var G__35501 = cljs.core.first.call(null,seq35499__$1);
var seq35499__$2 = cljs.core.next.call(null,seq35499__$1);
return hoplon.storage_atom.local_storage.cljs$core$IFn$_invoke$arity$variadic(G__35500,G__35501,seq35499__$2);
});

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

var G__35516 = (i__24560__auto___35515 + (1));
i__24560__auto___35515 = G__35516;
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__35511){
var map__35512 = p__35511;
var map__35512__$1 = ((((!((map__35512 == null)))?((((map__35512.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35512.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35512):map__35512);
var ignore_existing = cljs.core.get.call(null,map__35512__$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 (seq35508){
var G__35509 = cljs.core.first.call(null,seq35508);
var seq35508__$1 = cljs.core.next.call(null,seq35508);
var G__35510 = cljs.core.first.call(null,seq35508__$1);
var seq35508__$2 = cljs.core.next.call(null,seq35508__$1);
return hoplon.storage_atom.session_storage.cljs$core$IFn$_invoke$arity$variadic(G__35509,G__35510,seq35508__$2);
});

