jellyfin-web/dashboard-ui/bower_components/emby-apiclient/appstorage-localstorage.js
2017-04-28 18:31:47 -04:00

1 line
863 B
JavaScript

define([],function(){"use strict";function updateCache(instance){var cache=instance.cache;cache&&cache.put("data",new Response(JSON.stringify(instance.localData)))}function onCacheOpened(result){this.cache=result,this.localData={}}function MyStore(){try{self.caches&&caches.open("embydata").then(onCacheOpened.bind(this))}catch(err){console.log("Error opening cache: "+err)}}return MyStore.prototype.setItem=function(name,value){localStorage.setItem(name,value);var localData=this.localData;if(localData){var changed=localData[name]!==value;changed&&(localData[name]=value,updateCache(this))}},MyStore.prototype.getItem=function(name){return localStorage.getItem(name)},MyStore.prototype.removeItem=function(name){localStorage.removeItem(name);var localData=this.localData;localData&&(localData[name]=null,delete localData[name],updateCache(this))},new MyStore});