diff --git a/dist/lib/hooks/usePoll.d.ts b/dist/lib/hooks/usePoll.d.ts deleted file mode 100644 index c29767e..0000000 --- a/dist/lib/hooks/usePoll.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { PollWorkerProps } from "../types"; -export declare function usePoll(props: PollWorkerProps): { - data: any; - loading: boolean; - preload: boolean; - error: undefined; - update: boolean; -} | { - error: any; - loading: boolean; - preload: boolean; - data: import("../utils").UnknownDataResponseType; - update: boolean; -} | { - loading: any; - data: import("../utils").UnknownDataResponseType; - error?: Error | undefined; - preload: boolean; - update: boolean; -}; diff --git a/dist/lib/index.d.ts b/dist/lib/index.d.ts index 9d1c0df..4008f9a 100644 --- a/dist/lib/index.d.ts +++ b/dist/lib/index.d.ts @@ -1,3 +1,2 @@ export { useFetch } from './hooks/useFetch'; -export { usePoll } from './hooks/usePoll'; export { usePreFetch } from './hooks/usePreFetch'; diff --git a/dist/lib/utils/index.d.ts b/dist/lib/utils/index.d.ts index 90b50c4..01ce239 100644 --- a/dist/lib/utils/index.d.ts +++ b/dist/lib/utils/index.d.ts @@ -1,7 +1,6 @@ import type { createArrayOfUpdatesType } from "../types"; export * from "./state_tools"; export * from "./store_tools"; -export * from "./poll"; export declare const DAY: number; export declare function cleanupWorker(worker: Worker | undefined): void; export declare const dataExpired: (maxAge: number, timestamp?: number | undefined) => boolean; diff --git a/dist/lib/utils/poll.d.ts b/dist/lib/utils/poll.d.ts deleted file mode 100644 index 09da044..0000000 --- a/dist/lib/utils/poll.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface PollProps { - fn: () => Promise; - validate: (res: unknown) => boolean; - interval: number; - maxAttempts?: number; - attempts?: number; -} -export declare const poll: ({ fn, validate, interval, maxAttempts }: PollProps) => Promise; diff --git a/dist/queryPlus.es.js b/dist/queryPlus.es.js index 772e9f0..d523df6 100644 --- a/dist/queryPlus.es.js +++ b/dist/queryPlus.es.js @@ -19,7 +19,7 @@ var __spreadValues = (a, b) => { var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); import { useReducer, useRef, useEffect } from "react"; import "idb-keyval"; -const encodedJs = "dmFyIGs9T2JqZWN0LmRlZmluZVByb3BlcnR5LGo9T2JqZWN0LmRlZmluZVByb3BlcnRpZXM7dmFyIEE9T2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcnM7dmFyIFc9T2JqZWN0LmdldE93blByb3BlcnR5U3ltYm9sczt2YXIgUT1PYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LHY9T2JqZWN0LnByb3RvdHlwZS5wcm9wZXJ0eUlzRW51bWVyYWJsZTt2YXIgQj0oaCxkLGwpPT5kIGluIGg/ayhoLGQse2VudW1lcmFibGU6ITAsY29uZmlndXJhYmxlOiEwLHdyaXRhYmxlOiEwLHZhbHVlOmx9KTpoW2RdPWwsWj0oaCxkKT0+e2Zvcih2YXIgbCBpbiBkfHwoZD17fSkpUS5jYWxsKGQsbCkmJkIoaCxsLGRbbF0pO2lmKFcpZm9yKHZhciBsIG9mIFcoZCkpdi5jYWxsKGQsbCkmJkIoaCxsLGRbbF0pO3JldHVybiBofSxUPShoLGQpPT5qKGgsQShkKSk7KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2Z1bmN0aW9uIGgodCl7cmV0dXJuIG5ldyBQcm9taXNlKChlLG4pPT57dC5vbmNvbXBsZXRlPXQub25zdWNjZXNzPSgpPT5lKHQucmVzdWx0KSx0Lm9uYWJvcnQ9dC5vbmVycm9yPSgpPT5uKHQuZXJyb3IpfSl9ZnVuY3Rpb24gZCh0LGUpe2NvbnN0IG49aW5kZXhlZERCLm9wZW4odCk7bi5vbnVwZ3JhZGVuZWVkZWQ9KCk9Pm4ucmVzdWx0LmNyZWF0ZU9iamVjdFN0b3JlKGUpO2NvbnN0IGM9aChuKTtyZXR1cm4oYSxyKT0+Yy50aGVuKGk9PnIoaS50cmFuc2FjdGlvbihlLGEpLm9iamVjdFN0b3JlKGUpKSl9bGV0IGw7ZnVuY3R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lbGYucG9zdE1lc3NhZ2UoTyhhLG89PW51bGw/dm9pZCAwOm8uZGF0YSk/e3R5cGU6IkNBQ0hFRCJ9Ont0eXBlOiJQUkVfTE9BRCIsZGF0YTpvPT1udWxsP3ZvaWQgMDpvLmRhdGF9KX0pLmNhdGNoKG89Pntjb25zb2xlLmluZm8obz09bnVsbD92b2lkIDA6by5tZXNzYWdlKX0pLGZldGNoKHMsYz9UKGwoe30sYykse3NpZ25hbDpyfSk6e3NpZ25hbDpyfSkudGhlbihEKS50aGVuKEUpLmNhdGNoKFMpKSwodT09PSJQVVQifHx1PT09IlBPU1QiKSYmZmV0Y2gocyxjP1QobCh7fSxjKSx7c2lnbmFsOnJ9KTp7c2lnbmFsOnJ9KS50aGVuKEQpLnRoZW4obz0+e3A/ZmV0Y2gocC51cmwscC5vcHRpb25zKS50aGVuKEQpLnRoZW4oRSkuY2F0Y2goeT0+e3Rocm93IHl9KTpOKHMudG9TdHJpbmcoKSx5PT57bGV0IHg9RGF0ZS5ub3coKSxMPUEobykmJkEoeT09bnVsbD92b2lkIDA6eS5kYXRhKT9sKGwoe30seS5kYXRhKSxvKTpvO3JldHVybiBzZWxmLnBvc3RNZXNzYWdlKHt0eXBlOnUsZGF0YTpMfSkse3RpbWVzdGFtcDp4LG1heEFnZTpkLGRhdGE6TH19KS5jYXRjaCgoKT0+e2NvbnNvbGUuaW5mbygidXBkYXRlIHN0b3JlIGZhaWxlZCIpfSkuZmluYWxseSgoKT0+e3NlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6IkNPTVBMRVRFIn0pfSl9KS5jYXRjaChTKX19KX0pKCk7Cg=="; const blob = typeof window !== "undefined" && window.Blob && new Blob([atob(encodedJs)], { type: "text/javascript;charset=utf-8" }); function WorkerWrapper() { const objURL = blob && (window.URL || window.webkitURL).createObjectURL(blob); @@ -124,52 +124,6 @@ function useFetch() { fetchWorker }, state); } -function usePoll(props) { - const [state, dispatch] = useReducer(reducer, initialState); - const worker = useRef(new WorkerWrapper()); - useEffect(() => { - var _a, _b; - if (props && worker.current) { - dispatch({ - type: "loading", - loading: true - }); - (_a = worker.current) == null ? void 0 : _a.addEventListener("message", ({ - data: { - type, - data - } - }) => { - if (type === "COMPLETE") - dispatch({ - type: "loading", - loading: false - }); - else if (type === "DATA") - dispatch({ - type: "data", - data - }); - else - dispatch({ - type: "error", - error: new Error(type) - }); - }); - (_b = worker.current) == null ? void 0 : _b.postMessage(__spreadProps(__spreadValues({ - type: "poll" - }, props), { - existingData: state.data - })); - } - }, [props, worker.current]); - useEffect(() => { - return () => { - cleanupWorker(worker.current); - }; - }, []); - return __spreadValues({}, state); -} function usePreFetch(prefetch) { const worker = useRef(new WorkerWrapper()); useEffect(() => { @@ -190,4 +144,4 @@ function usePreFetch(prefetch) { }; }, []); } -export { useFetch, usePoll, usePreFetch }; +export { useFetch, usePreFetch }; diff --git a/dist/queryPlus.umd.js b/dist/queryPlus.umd.js index 8c75df8..7f8d72e 100644 --- a/dist/queryPlus.umd.js +++ b/dist/queryPlus.umd.js @@ -1 +1 @@ -(function(W,d){typeof exports=="object"&&typeof module!="undefined"?d(exports,require("react"),require("idb-keyval")):typeof define=="function"&&define.amd?define(["exports","react","idb-keyval"],d):(W=typeof globalThis!="undefined"?globalThis:W||self,d(W.queryPlus={},W.React))})(this,function(W,d){"use strict";var K=Object.defineProperty,H=Object.defineProperties;var F=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable;var u=(W,d,b)=>d in W?K(W,d,{enumerable:!0,configurable:!0,writable:!0,value:b}):W[d]=b,c=(W,d)=>{for(var b in d||(d={}))w.call(d,b)&&u(W,b,d[b]);if(S)for(var b of S(d))y.call(d,b)&&u(W,b,d[b]);return W},a=(W,d)=>H(W,F(d));const b="dmFyIGs9T2JqZWN0LmRlZmluZVByb3BlcnR5LGo9T2JqZWN0LmRlZmluZVByb3BlcnRpZXM7dmFyIEE9T2JqZWN0LmdldE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UKFooe30sbykse3NpZ25hbDpjfSk6e3NpZ25hbDpjfSkudGhlbihTKS50aGVuKHM9PnttP2ZldGNoKG0udXJsLG0ub3B0aW9ucykudGhlbihTKS50aGVuKHApLmNhdGNoKHk9Pnt0aHJvdyB5fSk6VihpLnRvU3RyaW5nKCkseT0+e2xldCBLPURhdGUubm93KCksSD1nKHMpJiZnKHk9PW51bGw/dm9pZCAwOnkuZGF0YSk/WihaKHt9LHkuZGF0YSkscyk6cztyZXR1cm4gc2VsZi5wb3N0TWVzc2FnZSh7dHlwZTpiLGRhdGE6SH0pLHt0aW1lc3RhbXA6SyxtYXhBZ2U6ZixkYXRhOkh9fSkuY2F0Y2goKCk9Pntjb25zb2xlLmluZm8oInVwZGF0ZSBzdG9yZSBmYWlsZWQiKX0pLmZpbmFsbHkoKCk9PntzZWxmLnBvc3RNZXNzYWdlKHt0eXBlOiJDT01QTEVURSJ9KX0pfSkuY2F0Y2goUil9fSl9KSgpOwo=",R=typeof window!="undefined"&&window.Blob&&new Blob([atob(b)],{type:"text/javascript;charset=utf-8"});function m(){const l=R&&(window.URL||window.webkitURL).createObjectURL(R);try{return l?new Worker(l,{}):new Worker("data:application/javascript;base64,"+b,{type:"module"})}finally{l&&(window.URL||window.webkitURL).revokeObjectURL(l)}}const t={data:void 0,error:void 0,loading:!1,preload:!1,update:!0};function s(l,Z){switch(Z.type){case"pre-load":return a(c({},l),{data:Z.data,loading:!1,preload:!0,error:void 0});case"data":return a(c({},l),{data:Z.data,loading:!1,preload:!1,error:void 0});case"error":return a(c({},l),{error:Z.error,loading:!1,preload:!1});case"loading":return a(c({},l),{loading:Z.loading});default:return l}}const T=24*60*60*1e3;function i(l){l==null||l.postMessage({type:"cancel"}),l==null||l.terminate(),l=void 0}const N=l=>l?encodeURI(l.toString()):void 0;function k(){const[l,Z]=d.useReducer(s,t),V=d.useRef(),e=async({url:G,options:Y,maxAge:p=T,middleware:h})=>{let n=V.current;Z({type:"loading",loading:!0}),n==null||n.addEventListener("message",({data:{type:o,data:U}})=>{switch(o){case"CACHED":case"COMPLETE":Z({type:"loading",loading:!1});break;case"DATA":Z({type:"data",data:U});break;case"PRE_LOAD":Z({type:"pre-load",data:U});break;default:Z({type:"error",error:new Error(o)});break}}),n==null||n.postMessage({type:"fetch",url:G,options:Y,existingData:l.data,middleware:N(h),maxAge:p})};return d.useEffect(()=>(V.current=new m,()=>{i(V.current)}),[]),c({fetchWorker:e},l)}function J(l){const[Z,V]=d.useReducer(s,t),e=d.useRef(new m);return d.useEffect(()=>{var G,Y;l&&e.current&&(V({type:"loading",loading:!0}),(G=e.current)==null||G.addEventListener("message",({data:{type:p,data:h}})=>{V(p==="COMPLETE"?{type:"loading",loading:!1}:p==="DATA"?{type:"data",data:h}:{type:"error",error:new Error(p)})}),(Y=e.current)==null||Y.postMessage(a(c({type:"poll"},l),{existingData:Z.data})))},[l,e.current]),d.useEffect(()=>()=>{i(e.current)},[]),c({},Z)}function X(l){const Z=d.useRef(new m);d.useEffect(()=>{var V;l&&Z.current&&((V=Z.current)==null||V.postMessage({type:"pre-fetch",prefetch:l.map(e=>a(c({},e),{middleware:N(e.middleware)}))}))},[l,Z.current]),d.useEffect(()=>(Z.current=new m,()=>{i(Z.current)}),[])}W.useFetch=k,W.usePoll=J,W.usePreFetch=X,Object.defineProperties(W,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); +(function(l,d){typeof exports=="object"&&typeof module!="undefined"?d(exports,require("react"),require("idb-keyval")):typeof define=="function"&&define.amd?define(["exports","react","idb-keyval"],d):(l=typeof globalThis!="undefined"?globalThis:l||self,d(l.queryPlus={},l.React))})(this,function(l,d){"use strict";var J=Object.defineProperty,V=Object.defineProperties;var N=Object.getOwnPropertyDescriptors;var Y=Object.getOwnPropertySymbols;var r=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var s=(l,d,b)=>d in l?J(l,d,{enumerable:!0,configurable:!0,writable:!0,value:b}):l[d]=b,m=(l,d)=>{for(var b in d||(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kYXRhKSxvKTpvO3JldHVybiBzZWxmLnBvc3RNZXNzYWdlKHt0eXBlOnUsZGF0YTpMfSkse3RpbWVzdGFtcDp4LG1heEFnZTpkLGRhdGE6TH19KS5jYXRjaCgoKT0+e2NvbnNvbGUuaW5mbygidXBkYXRlIHN0b3JlIGZhaWxlZCIpfSkuZmluYWxseSgoKT0+e3NlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6IkNPTVBMRVRFIn0pfSl9KS5jYXRjaChTKX19KX0pKCk7Cg==",u=typeof window!="undefined"&&window.Blob&&new Blob([atob(b)],{type:"text/javascript;charset=utf-8"});function p(){const e=u&&(window.URL||window.webkitURL).createObjectURL(u);try{return e?new Worker(e,{}):new Worker("data:application/javascript;base64,"+b,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const h={data:void 0,error:void 0,loading:!1,preload:!1,update:!0};function y(e,c){switch(c.type){case"pre-load":return n(m({},e),{data:c.data,loading:!1,preload:!0,error:void 0});case"data":return n(m({},e),{data:c.data,loading:!1,preload:!1,error:void 0});case"error":return n(m({},e),{error:c.error,loading:!1,preload:!1});case"loading":return n(m({},e),{loading:c.loading});default:return e}}const R=24*60*60*1e3;function G(e){e==null||e.postMessage({type:"cancel"}),e==null||e.terminate(),e=void 0}const K=e=>e?encodeURI(e.toString()):void 0;function T(){const[e,c]=d.useReducer(y,h),Z=d.useRef(),i=async({url:k,options:S,maxAge:W=R,middleware:I})=>{let o=Z.current;c({type:"loading",loading:!0}),o==null||o.addEventListener("message",({data:{type:a,data:t}})=>{switch(a){case"CACHED":case"COMPLETE":c({type:"loading",loading:!1});break;case"DATA":c({type:"data",data:t});break;case"PRE_LOAD":c({type:"pre-load",data:t});break;default:c({type:"error",error:new Error(a)});break}}),o==null||o.postMessage({type:"fetch",url:k,options:S,existingData:e.data,middleware:K(I),maxAge:W})};return d.useEffect(()=>(Z.current=new p,()=>{G(Z.current)}),[]),m({fetchWorker:i},e)}function X(e){const c=d.useRef(new p);d.useEffect(()=>{var Z;e&&c.current&&((Z=c.current)==null||Z.postMessage({type:"pre-fetch",prefetch:e.map(i=>n(m({},i),{middleware:K(i.middleware)}))}))},[e,c.current]),d.useEffect(()=>(c.current=new p,()=>{G(c.current)}),[])}l.useFetch=T,l.usePreFetch=X,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); diff --git a/src/lib/hooks/usePoll.tsx b/src/lib/hooks/usePoll.tsx deleted file mode 100644 index dce4f8e..0000000 --- a/src/lib/hooks/usePoll.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import { useRef, useEffect, useReducer } from "react"; - -import FetchWorker from '../workers/fetch_worker.js?worker&inline' -import { cleanupWorker, initialState, reducer } from "../utils"; - -import type { WorkerResponseType, PollWorkerProps } from "../types"; - -export function usePoll(props: PollWorkerProps) { - const [state, dispatch] = useReducer(reducer, initialState); - const worker = useRef(new FetchWorker()); - - useEffect(() => { - if(props && worker.current) { - dispatch({ type: 'loading', loading: true }) - worker.current?.addEventListener('message', ({ data: { type, data } }: WorkerResponseType) => { - if(type === 'COMPLETE') dispatch({ type: 'loading', loading: false }); - else if(type === 'DATA') dispatch({ type: 'data', data }); - else dispatch({ type: 'error', error: new Error(type) }); - }) - worker.current?.postMessage({ type: 'poll', ...props, existingData: state.data }); - } - }, [props, worker.current]); - useEffect(() => { - return () => { - cleanupWorker(worker.current); - } - }, []); - return { ...state! }; -}; diff --git a/src/lib/hooks/useStore.tsx b/src/lib/hooks/useStore.tsx deleted file mode 100644 index c2743ce..0000000 --- a/src/lib/hooks/useStore.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import { useRef, useEffect, useState } from "react"; - -import StoreWorker from '../workers/store_worker.js?worker&inline' -import { cleanupWorker } from "../utils"; - -import type { WorkerResponseType } from "../types"; - -export function useData(key: string) { - const [data, setData] = useState() - const worker = useRef(new StoreWorker()); - // build the postMessage functions - - useEffect(() => { - return () => { - cleanupWorker(worker.current); - } - }, []); - return [data]; -}; diff --git a/src/lib/index.ts b/src/lib/index.ts index 3128e79..2c8a84d 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,3 +1,2 @@ export {useFetch} from './hooks/useFetch'; -export {usePoll} from './hooks/usePoll'; export {usePreFetch} from './hooks/usePreFetch'; \ No newline at end of file diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 0ac111b..83b0afc 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -2,7 +2,6 @@ import type { createArrayOfUpdatesType, ArrayOfStringAnyTuple, StringAnyTuple } export * from "./state_tools"; export * from "./store_tools"; -export * from "./poll"; export const DAY = 24 * 60 * 60 * 1000; diff --git a/src/lib/utils/poll.ts b/src/lib/utils/poll.ts deleted file mode 100644 index c7e9266..0000000 --- a/src/lib/utils/poll.ts +++ /dev/null @@ -1,35 +0,0 @@ -export interface PollProps { - fn: () => Promise; - validate: (res: unknown) => boolean; - interval: number; - maxAttempts?: number; - attempts?: number -} - -export const poll: ( - { fn, validate, interval, maxAttempts }: PollProps, -) => Promise = async ({ fn, validate, interval, maxAttempts, attempts=0 }) => { - async function executePoll( - resolve: (value: unknown) => void, - reject: (reason?: any) => void, - ) { - try { - const result = await fn(); - attempts++; - if (!validate(result)) { - return resolve(result); - } else if (maxAttempts && (attempts === maxAttempts)) { - return reject(new Error("Exceeded max attempts")); - } else { - await setTimeout(executePoll, interval, resolve, reject); - } - } catch (error) { - console.error( - `polling Error: ${ - (error as Error)?.message || "connection failed" - }`, - ); - } - } - return new Promise(executePoll); -}; diff --git a/src/lib/workers/fetch_worker.ts b/src/lib/workers/fetch_worker.ts index 7ded2fe..145b749 100644 --- a/src/lib/workers/fetch_worker.ts +++ b/src/lib/workers/fetch_worker.ts @@ -7,9 +7,7 @@ import { store, } from "../utils"; -import PollWorker from "./polling_worker.js?worker&inline"; - -import type { WorkerResponseType, ValueType, FetchWorkerRequestType } from "../types"; +import type { ValueType, FetchWorkerRequestType } from "../types"; const { remove, getData, setData, updateData } = store(); @@ -33,53 +31,10 @@ self.addEventListener( const { type } = event.data; let controller: AbortController | undefined = new AbortController(); let signal = controller?.signal; - let pollWorker = new PollWorker(); + if (type === "cancel") { controller?.abort(); - pollWorker?.postMessage({ type: "cancel" }); - pollWorker.terminate(); - } - if (type === "poll") { - let { - existingData, - url, - options, - interval, - maxAttempts, - compareKeys, - } = event.data; - fetch(url, options ? { ...options, signal } : { signal }) - .then(handleResponse) - .then( - (data: unknown) => { - if (isMatch(existingData, data, compareKeys)) { - self.postMessage({ type: "CACHED", data }); - } else { - setData(url, { timestamp: Date.now(), data }); - self.postMessage({ type: "DATA", data }); - } - }, - ) - .catch(handleError) - .finally(() => { - pollWorker?.postMessage({ - type, - url, - options, - interval, - maxAttempts, - existingData, - compareKeys, - }); - }); - pollWorker?.addEventListener( - "message", - ({ data }: WorkerResponseType) => { - self.postMessage(data); - }, - ); } - if (type === "pre-fetch") { let { prefetch } = event.data; prefetch.forEach(({middleware, url, options, maxAge}:FetchWorkerRequestType) => { diff --git a/src/lib/workers/polling_worker.ts b/src/lib/workers/polling_worker.ts deleted file mode 100644 index 8f1cd92..0000000 --- a/src/lib/workers/polling_worker.ts +++ /dev/null @@ -1,35 +0,0 @@ -import {isMatch, poll} from "../utils" -self.addEventListener('message', (event) => { - const { type } = event.data; - let controller: AbortController | undefined = new AbortController(); - let signal = controller?.signal; - if (type === 'cancel') { - controller?.abort(); - } - if (type === 'poll') { - const { url, options, interval, maxAttempts, existingData, compareKeys } = event.data; - const validate = (newJson: unknown) => !isMatch(existingData, newJson, compareKeys); - const getData = () => fetch(url, options ? {...options, signal} : {signal}).then( - (response) => { - if (!response.ok || response.status === 404) { - throw new Error(`HTTP error! Status: ${ response.status }`); - } - if (response.status === 403) { - throw new Error(`Unauthorized!`); - } - return response.json(); - } - ) - poll({ - fn: getData, - interval, - maxAttempts, - validate - }) - .then(data => { - self.postMessage({type: 'DATA', data}); - }).catch(error => { - self.postMessage({type: error.message || 'Unknown error'}); - }) - } -}); \ No newline at end of file diff --git a/src/lib/workers/store_worker.ts b/src/lib/workers/store_worker.ts deleted file mode 100644 index 9f4e1ed..0000000 --- a/src/lib/workers/store_worker.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { dataExpired, store } from "../utils"; - -const { remove, getData, setData, updateData } = store(); - -self.addEventListener( - "message", - (event) => { - let { - type, - url, - maxAge, - newData - } = event.data; - if(type === "get") { - getData(url).then(data => { - if(dataExpired(data, maxAge)) { - self.postMessage({ - type: "expired", - url, - }); - } else { - self.postMessage({ - type: "get-success", - url, - data, - }); - } - }).catch((error) => { - self.postMessage({ - type: "error", - error, - url, - }); - }) - } - if(type === "delete") { - remove(url).then(() => { - self.postMessage({ - type: "delete-success", - url, - }); - }).catch((error) => { - self.postMessage({ - type: "error", - error, - url, - }); - }) - } - if(type === "set") { - setData(url, newData).then(() => { - self.postMessage({ - type: "set-success", - url, - }); - }).catch((error) => { - self.postMessage({ - type: "error", - error, - url, - }); - }) - } - if(type === "update") { - updateData(url, newData).then(() => { - self.postMessage({ - type: "update-success", - url, - }); - }).catch((error) => { - self.postMessage({ - type: "error", - error, - url, - }); - }) - } - }, -);