// 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___35387 = arguments.length;
var i__24370__auto___35388 = (0);
while(true){
if((i__24370__auto___35388 < len__24369__auto___35387)){
args__24376__auto__.push((arguments[i__24370__auto___35388]));

var G__35389 = (i__24370__auto___35388 + (1));
i__24370__auto___35388 = G__35389;
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__35383){
var map__35384 = p__35383;
var map__35384__$1 = ((((!((map__35384 == null)))?((((map__35384.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35384.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35384):map__35384);
var ignore_existing = cljs.core.get.call(null,map__35384__$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__35386 = atom;
cljs.core.add_watch.call(null,G__35386,new cljs.core.Keyword("hoplon.storage-atom","storage-watch","hoplon.storage-atom/storage-watch",-690647421),((function (G__35386,existing,map__35384,map__35384__$1,ignore_existing){
return (function (p1__35377_SHARP_,p2__35378_SHARP_,p3__35379_SHARP_,p4__35376_SHARP_){
return hoplon.storage_atom._commit_BANG_.call(null,backend,p4__35376_SHARP_);
});})(G__35386,existing,map__35384,map__35384__$1,ignore_existing))
);

return G__35386;
});

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

hoplon.storage_atom.store.cljs$lang$applyTo = (function (seq35380){
var G__35381 = cljs.core.first.call(null,seq35380);
var seq35380__$1 = cljs.core.next.call(null,seq35380);
var G__35382 = cljs.core.first.call(null,seq35380__$1);
var seq35380__$2 = cljs.core.next.call(null,seq35380__$1);
return hoplon.storage_atom.store.cljs$core$IFn$_invoke$arity$variadic(G__35381,G__35382,seq35380__$2);
});

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

var G__35399 = (i__24370__auto___35398 + (1));
i__24370__auto___35398 = G__35399;
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__35394){
var map__35395 = p__35394;
var map__35395__$1 = ((((!((map__35395 == null)))?((((map__35395.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35395.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35395):map__35395);
var ignore_existing = cljs.core.get.call(null,map__35395__$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 (seq35390){
var G__35391 = cljs.core.first.call(null,seq35390);
var seq35390__$1 = cljs.core.next.call(null,seq35390);
var G__35392 = cljs.core.first.call(null,seq35390__$1);
var seq35390__$2 = cljs.core.next.call(null,seq35390__$1);
var G__35393 = cljs.core.first.call(null,seq35390__$2);
var seq35390__$3 = cljs.core.next.call(null,seq35390__$2);
return hoplon.storage_atom.html_storage.cljs$core$IFn$_invoke$arity$variadic(G__35391,G__35392,G__35393,seq35390__$3);
});

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

var G__35408 = (i__24370__auto___35407 + (1));
i__24370__auto___35407 = G__35408;
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__35403){
var map__35404 = p__35403;
var map__35404__$1 = ((((!((map__35404 == null)))?((((map__35404.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35404.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35404):map__35404);
var ignore_existing = cljs.core.get.call(null,map__35404__$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 (seq35400){
var G__35401 = cljs.core.first.call(null,seq35400);
var seq35400__$1 = cljs.core.next.call(null,seq35400);
var G__35402 = cljs.core.first.call(null,seq35400__$1);
var seq35400__$2 = cljs.core.next.call(null,seq35400__$1);
return hoplon.storage_atom.local_storage.cljs$core$IFn$_invoke$arity$variadic(G__35401,G__35402,seq35400__$2);
});

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

var G__35417 = (i__24370__auto___35416 + (1));
i__24370__auto___35416 = G__35417;
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__35412){
var map__35413 = p__35412;
var map__35413__$1 = ((((!((map__35413 == null)))?((((map__35413.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35413.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35413):map__35413);
var ignore_existing = cljs.core.get.call(null,map__35413__$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 (seq35409){
var G__35410 = cljs.core.first.call(null,seq35409);
var seq35409__$1 = cljs.core.next.call(null,seq35409);
var G__35411 = cljs.core.first.call(null,seq35409__$1);
var seq35409__$2 = cljs.core.next.call(null,seq35409__$1);
return hoplon.storage_atom.session_storage.cljs$core$IFn$_invoke$arity$variadic(G__35410,G__35411,seq35409__$2);
});

