UNPKG

@vueuse/integrations

Version:
2 lines (1 loc) 771 B
(function(f,h,s,t){"use strict";function d(r,i,V={}){const{flush:p="pre",deep:D=!0,shallow:v=!1,onError:c=e=>{console.error(e)},writeDefaults:I=!0,serializer:u={read:e=>e,write:e=>e}}=V,o=t.shallowRef(!1),a=(v?t.shallowRef:t.ref)(i),l=t.toValue(i);async function R(){try{const e=await s.get(r);if(e===void 0){if(l!=null&&I){const n=u.write(l);await s.set(r,n)}}else a.value=u.read(e)}catch(e){c(e)}o.value=!0}R();async function w(){try{if(a.value==null)await s.del(r);else{const e=t.toRaw(a.value),n=u.write(e);await s.update(r,()=>n)}}catch(e){c(e)}}const{pause:U,resume:m}=h.watchPausable(a,()=>w(),{flush:p,deep:D});async function y(e){U(),a.value=e,await w(),m()}return{set:y,isFinished:o,data:a}}f.useIDBKeyval=d})(this.VueUse=this.VueUse||{},VueUse,idbKeyval,Vue);