From e4f098997f48fd136df42f8c5c422ce612168cb0 Mon Sep 17 00:00:00 2001 From: Rod Lewis Date: Sun, 26 Jun 2022 21:05:10 +0800 Subject: [PATCH 1/5] add polling --- dist/lib/hooks/useFetch.d.ts | 19 +++- dist/lib/utils/index.d.ts | 1 + dist/lib/utils/poll.d.ts | 8 ++ dist/query-plus.es.js | 53 ++++++++- dist/query-plus.umd.js | 2 +- src/lib/hooks/useFetch.tsx | 30 ++++-- src/lib/utils/index.ts | 1 + src/lib/utils/poll.ts | 35 ++++++ src/lib/workers/fetch_worker.ts | 171 +++++++++++++++++++++--------- src/lib/workers/polling_worker.ts | 35 ++++++ 10 files changed, 292 insertions(+), 63 deletions(-) create mode 100644 dist/lib/utils/poll.d.ts create mode 100644 src/lib/utils/poll.ts create mode 100644 src/lib/workers/polling_worker.ts diff --git a/dist/lib/hooks/useFetch.d.ts b/dist/lib/hooks/useFetch.d.ts index 2d697ff..3f402bb 100644 --- a/dist/lib/hooks/useFetch.d.ts +++ b/dist/lib/hooks/useFetch.d.ts @@ -1,6 +1,6 @@ import { UnknownDataResponseType } from "../utils"; export interface FetchWorkerProps { - fetchOptions?: RequestInit | undefined; + options?: RequestInit | undefined; maxAge?: number; middleware?: (data: UnknownDataResponseType) => UnknownDataResponseType; url: RequestInfo | URL; @@ -9,6 +9,14 @@ export interface FetchWorkerProps { options?: RequestInit | undefined; }; } +export interface PollWorkerProps { + url: RequestInfo | URL; + interval: number; + options?: RequestInit | undefined; + maxAttempts?: number; + existingData?: number; + compareKeys?: string[]; +} /** * useFetch is a React hook that can be initialized with no params. * @example const { data, error, loading, fetchWorker } = useFetch() @@ -25,19 +33,22 @@ export declare function useFetch(): { preload: boolean; error: undefined; update: boolean; - fetchWorker: ({ url, fetchOptions, maxAge, middleware }: FetchWorkerProps) => Promise; + fetchWorker: ({ url, options, maxAge, middleware }: FetchWorkerProps) => Promise; + pollWorker: ({ url, interval, options, maxAttempts, compareKeys }: PollWorkerProps) => Promise; } | { error: any; loading: boolean; preload: boolean; data: UnknownDataResponseType; update: boolean; - fetchWorker: ({ url, fetchOptions, maxAge, middleware }: FetchWorkerProps) => Promise; + fetchWorker: ({ url, options, maxAge, middleware }: FetchWorkerProps) => Promise; + pollWorker: ({ url, interval, options, maxAttempts, compareKeys }: PollWorkerProps) => Promise; } | { loading: any; data: UnknownDataResponseType; error?: Error | undefined; preload: boolean; update: boolean; - fetchWorker: ({ url, fetchOptions, maxAge, middleware }: FetchWorkerProps) => Promise; + fetchWorker: ({ url, options, maxAge, middleware }: FetchWorkerProps) => Promise; + pollWorker: ({ url, interval, options, maxAttempts, compareKeys }: PollWorkerProps) => Promise; }; diff --git a/dist/lib/utils/index.d.ts b/dist/lib/utils/index.d.ts index 50d46ae..9a8a5bb 100644 --- a/dist/lib/utils/index.d.ts +++ b/dist/lib/utils/index.d.ts @@ -1,4 +1,5 @@ export * from "./state_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 new file mode 100644 index 0000000..09da044 --- /dev/null +++ b/dist/lib/utils/poll.d.ts @@ -0,0 +1,8 @@ +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/query-plus.es.js b/dist/query-plus.es.js index ed6a908..5fdcc86 100644 --- a/dist/query-plus.es.js +++ b/dist/query-plus.es.js @@ -18,7 +18,7 @@ var __spreadValues = (a, b) => { }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); import { useReducer, useRef, useEffect } from "react"; -const encodedJs = "dmFyIGI9T2JqZWN0LmRlZmluZVByb3BlcnR5LEk9T2JqZWN0LmRlZmluZVByb3BlcnRpZXM7dmFyIFE9T2JqZWN0LmdldE93blByb3BlcnR5RGVzY3J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x8Wj09PSJQT1NUIikmJmZldGNoKGksaD9HKGYoe30saCkse3NpZ25hbDpjfSk6e3NpZ25hbDpjfSkudGhlbih5KS50aGVuKHM9PnttP2ZldGNoKG0udXJsLG0ub3B0aW9ucykudGhlbih5KS50aGVuKHApLmNhdGNoKGI9Pnt0aHJvdyBifSk6VihpLnRvU3RyaW5nKCksYj0+e2xldCBFPURhdGUubm93KCksSD1TKHMpJiZTKGI9PW51bGw/dm9pZCAwOmIuZGF0YSk/ZihmKHt9LGIuZGF0YSkscyk6cztyZXR1cm4gc2VsZi5wb3N0TWVzc2FnZSh7dHlwZTpaLGRhdGE6SH0pLHt0aW1lc3RhbXA6RSxtYXhBZ2U6VCxkYXRhOkh9fSkuY2F0Y2goKCk9Pntjb25zb2xlLmluZm8oInVwZGF0ZSBzdG9yZSBmYWlsZWQiKX0pLmZpbmFsbHkoKCk9PntzZWxmLnBvc3RNZXNzYWdlKHt0eXBlOiJDT01QTEVURSJ9KX0pfSkuY2F0Y2goUil9fSl9KSgpOwo="; 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); @@ -61,7 +61,7 @@ function useFetch() { const workerRef = useRef(); const fetchWorker = async ({ url, - fetchOptions, + options, maxAge = DAY, middleware }) => { @@ -108,12 +108,56 @@ function useFetch() { worker == null ? void 0 : worker.postMessage({ type: "fetch", url, - fetchOptions, + options, existingData: state.data, middleware: serializedMw, maxAge }); }; + const pollWorker = async ({ + url, + interval = 5e3, + options, + maxAttempts = 100, + compareKeys + }) => { + let worker = workerRef.current; + dispatch({ + type: "loading", + loading: true + }); + worker == null ? void 0 : worker.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) + }); + }); + worker == null ? void 0 : worker.postMessage({ + type: "poll", + url, + interval, + maxAttempts, + options, + existingData: state.data, + compareKeys + }); + }; useEffect(() => { workerRef.current = new WorkerWrapper(); return () => { @@ -121,7 +165,8 @@ function useFetch() { }; }, []); return __spreadValues({ - fetchWorker + fetchWorker, + pollWorker }, state); } export { useFetch }; diff --git a/dist/query-plus.umd.js b/dist/query-plus.umd.js index 03662be..0373c80 100644 --- a/dist/query-plus.umd.js +++ b/dist/query-plus.umd.js @@ -1 +1 @@ -(function(e,l){typeof exports=="object"&&typeof module!="undefined"?l(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],l):(e=typeof globalThis!="undefined"?globalThis:e||self,l(e["query-plus"]={},e.React))})(this,function(e,l){"use strict";var I=Object.defineProperty,k=Object.defineProperties;var C=Object.getOwnPropertyDescriptors;var G=Object.getOwnPropertySymbols;var P=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var t=(e,l,c)=>l in e?I(e,l,{enumerable:!0,configurable:!0,writable:!0,value:c}):e[l]=c,i=(e,l)=>{for(var c in l||(l={}))P.call(l,c)&&t(e,c,l[c]);if(G)for(var c of G(l))J.call(l,c)&&t(e,c,l[c]);return e},b=(e,l)=>k(e,C(l));const c="dmFyIGI9T2JqZWN0LmRlZmluZVByb3BlcnR5LEk9T2JqZWN0LmRlZmluZVByb3BlcnRpZXM7dmFyIFE9T2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcnM7dmFyIEw9T2JqZWN0LmdldE93blByb3BlcnR5U3ltYm9sczt2YXIgVz1PYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LFg9T2JqZWN0LnByb3RvdHlwZS5wcm9wZXJ0eUlzRW51bWVyYWJsZTt2YXIgUj0oYSxjLGkpPT5jIGluIGE/YihhLGMse2VudW1lcmFibGU6ITAsY29uZmlndXJhYmxlOiEwLHdyaXRhYmxlOiEwLHZhbHVlOml9KTphW2NdPWksZz0oYSxjKT0+e2Zvcih2YXIgaSBpbiBjfHwo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U6dSxkYXRhOnh9KSx7dGltZXN0YW1wOkIsbWF4QWdlOkMsZGF0YTp4fX0pLmNhdGNoKCgpPT57Y29uc29sZS5pbmZvKCJ1cGRhdGUgc3RvcmUgZmFpbGVkIil9KS5maW5hbGx5KCgpPT57c2VsZi5wb3N0TWVzc2FnZSh7dHlwZToiQ09NUExFVEUifSl9KX0pLmNhdGNoKEQpfX0pfSkoKTsK",n=typeof window!="undefined"&&window.Blob&&new Blob([atob(c)],{type:"text/javascript;charset=utf-8"});function y(){const d=n&&(window.URL||window.webkitURL).createObjectURL(n);try{return d?new Worker(d,{}):new Worker("data:application/javascript;base64,"+c,{type:"module"})}finally{d&&(window.URL||window.webkitURL).revokeObjectURL(d)}}const K={data:void 0,error:void 0,loading:!1,preload:!1,update:!0};function Y(d,Z){switch(Z.type){case"pre-load":return b(i({},d),{data:Z.data,loading:!1,preload:!0,error:void 0});case"data":return b(i({},d),{data:Z.data,loading:!1,preload:!1,error:void 0});case"error":return b(i({},d),{error:Z.error,loading:!1,preload:!1});case"loading":return b(i({},d),{loading:Z.loading});default:return d}}const s=24*60*60*1e3;function h(d){d==null||d.postMessage({type:"cancel"}),d==null||d.terminate(),d=void 0}const R=d=>encodeURI(d.toString());function X(){const[d,Z]=l.useReducer(Y,K),m=l.useRef(),L=async({url:S,fetchOptions:W,maxAge:T=s,middleware:o})=>{let p=m.current;Z({type:"loading",loading:!0}),p==null||p.addEventListener("message",({data:{type:u,data:a}})=>{switch(u){case"CACHED":case"COMPLETE":Z({type:"loading",loading:!1});break;case"DATA":Z({type:"data",data:a});break;case"PRE_LOAD":Z({type:"pre-load",data:a});break;default:Z({type:"error",error:new Error(u)});break}});let V=o?R(o):void 0;p==null||p.postMessage({type:"fetch",url:S,fetchOptions:W,existingData:d.data,middleware:V,maxAge:T})};return l.useEffect(()=>(m.current=new y,()=>{h(m.current)}),[]),i({fetchWorker:L},d)}e.useFetch=X,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); +(function(Z,d){typeof exports=="object"&&typeof module!="undefined"?d(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],d):(Z=typeof globalThis!="undefined"?globalThis:Z||self,d(Z["query-plus"]={},Z.React))})(this,function(Z,d){"use strict";var u=Object.defineProperty,K=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable;var t=(Z,d,a)=>d in Z?u(Z,d,{enumerable:!0,configurable:!0,writable:!0,value:a}):Z[d]=a,c=(Z,d)=>{for(var a in d||(d={}))y.call(d,a)&&t(Z,a,d[a]);if(U)for(var a of U(d))L.call(d,a)&&t(Z,a,d[a]);return Z},m=(Z,d)=>K(Z,H(d));const a="dmFyIGs9T2JqZWN0LmRlZmluZVByb3BlcnR5LGo9T2JqZWN0LmRlZmluZVByb3BlcnRpZXM7dmFyIEE9T2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcnM7dmFyIFc9T2JqZWN0LmdldE93blByb3BlcnR5U3ltYm9sczt2YXIgUT1PYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LHY9T2JqZWN0LnByb3RvdHlwZS5wcm9wZXJ0eUlzRW51bWVyYWJsZTt2YXIgQj0ocixhLGwpPT5hIGluIHI/ayhyLGEse2VudW1lcmFibGU6ITAsY29uZmlndXJhYmxlOiEwLHdyaXRhYmxlOiEwLHZhbHVlOmx9KTpyW2FdPWwsZj0ocixhKT0+e2Zvcih2YXIgbCBpbiBhfHwoYT17fSkpUS5jYWxsKGEsbCkmJkIocixsLGFbbF0pO2lmKFcpZm9yKHZhciBsIG9mIFcoYSkpdi5jYWxsKGEsbCkmJkIocixsLGFbbF0pO3JldHVybiByfSxHPShyLGEpPT5qKHIsQShhKSk7KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2Z1bmN0aW9uIHIodCl7cmV0dXJuIG5ldyBQcm9taXNlKChlLG4pPT57dC5vb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0ub3B0aW9ucykudGhlbih5KS50aGVuKHApLmNhdGNoKGI9Pnt0aHJvdyBifSk6VihpLnRvU3RyaW5nKCksYj0+e2xldCBFPURhdGUubm93KCksSD1TKHMpJiZTKGI9PW51bGw/dm9pZCAwOmIuZGF0YSk/ZihmKHt9LGIuZGF0YSkscyk6cztyZXR1cm4gc2VsZi5wb3N0TWVzc2FnZSh7dHlwZTpaLGRhdGE6SH0pLHt0aW1lc3RhbXA6RSxtYXhBZ2U6VCxkYXRhOkh9fSkuY2F0Y2goKCk9Pntjb25zb2xlLmluZm8oInVwZGF0ZSBzdG9yZSBmYWlsZWQiKX0pLmZpbmFsbHkoKCk9PntzZWxmLnBvc3RNZXNzYWdlKHt0eXBlOiJDT01QTEVURSJ9KX0pfSkuY2F0Y2goUil9fSl9KSgpOwo=",N=typeof window!="undefined"&&window.Blob&&new Blob([atob(a)],{type:"text/javascript;charset=utf-8"});function o(){const l=N&&(window.URL||window.webkitURL).createObjectURL(N);try{return l?new Worker(l,{}):new Worker("data:application/javascript;base64,"+a,{type:"module"})}finally{l&&(window.URL||window.webkitURL).revokeObjectURL(l)}}const S={data:void 0,error:void 0,loading:!1,preload:!1,update:!0};function h(l,W){switch(W.type){case"pre-load":return m(c({},l),{data:W.data,loading:!1,preload:!0,error:void 0});case"data":return m(c({},l),{data:W.data,loading:!1,preload:!1,error:void 0});case"error":return m(c({},l),{error:W.error,loading:!1,preload:!1});case"loading":return m(c({},l),{loading:W.loading});default:return l}}const s=24*60*60*1e3;function J(l){l==null||l.postMessage({type:"cancel"}),l==null||l.terminate(),l=void 0}const F=l=>encodeURI(l.toString());function X(){const[l,W]=d.useReducer(h,S),e=d.useRef(),T=async({url:R,options:n,maxAge:i=s,middleware:G})=>{let V=e.current;W({type:"loading",loading:!0}),V==null||V.addEventListener("message",({data:{type:p,data:Y}})=>{switch(p){case"CACHED":case"COMPLETE":W({type:"loading",loading:!1});break;case"DATA":W({type:"data",data:Y});break;case"PRE_LOAD":W({type:"pre-load",data:Y});break;default:W({type:"error",error:new Error(p)});break}});let b=G?F(G):void 0;V==null||V.postMessage({type:"fetch",url:R,options:n,existingData:l.data,middleware:b,maxAge:i})},k=async({url:R,interval:n=5e3,options:i,maxAttempts:G=100,compareKeys:V})=>{let b=e.current;W({type:"loading",loading:!0}),b==null||b.addEventListener("message",({data:{type:p,data:Y}})=>{W(p==="COMPLETE"?{type:"loading",loading:!1}:p==="DATA"?{type:"data",data:Y}:{type:"error",error:new Error(p)})}),b==null||b.postMessage({type:"poll",url:R,interval:n,maxAttempts:G,options:i,existingData:l.data,compareKeys:V})};return d.useEffect(()=>(e.current=new o,()=>{J(e.current)}),[]),c({fetchWorker:T,pollWorker:k},l)}Z.useFetch=X,Object.defineProperties(Z,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); diff --git a/src/lib/hooks/useFetch.tsx b/src/lib/hooks/useFetch.tsx index d50ff2d..e467b1e 100644 --- a/src/lib/hooks/useFetch.tsx +++ b/src/lib/hooks/useFetch.tsx @@ -1,7 +1,7 @@ import { useRef, useEffect, useReducer } from "react"; import FetchWorker from '../workers/fetch_worker.js?worker&inline' -import { cleanupWorker, DAY, initialState, isObject, reducer, serializeFunction, UnknownDataResponseType } from "../utils"; +import { cleanupWorker, DAY, initialState, reducer, serializeFunction, UnknownDataResponseType } from "../utils"; type WorkerResponseType = MessageEvent<{ @@ -10,7 +10,7 @@ type WorkerResponseType = MessageEvent<{ }> export interface FetchWorkerProps { - fetchOptions?: RequestInit | undefined + options?: RequestInit | undefined maxAge?: number middleware?: (data: UnknownDataResponseType) => UnknownDataResponseType url: RequestInfo | URL @@ -25,6 +25,14 @@ export interface FetchWorkerProps { options?: RequestInit | undefined } } +export interface PollWorkerProps { + url: RequestInfo | URL + interval: number, + options?: RequestInit | undefined + maxAttempts?: number, + existingData?: number, + compareKeys?: string[] +} /** * useFetch is a React hook that can be initialized with no params. * @example const { data, error, loading, fetchWorker } = useFetch() @@ -38,8 +46,8 @@ export interface FetchWorkerProps { export function useFetch() { const [state, dispatch] = useReducer(reducer, initialState); const workerRef = useRef(); - - const fetchWorker = async ({ url, fetchOptions, maxAge = DAY, middleware }: FetchWorkerProps) => { + + const fetchWorker = async ({ url, options, maxAge = DAY, middleware }: FetchWorkerProps) => { let worker = workerRef.current; dispatch({ type: 'loading', loading: true }); @@ -61,7 +69,17 @@ export function useFetch() { } }); let serializedMw = middleware ? serializeFunction(middleware) : undefined - worker?.postMessage({ type: 'fetch', url, fetchOptions, existingData: state.data, middleware: serializedMw, maxAge }); + worker?.postMessage({ type: 'fetch', url, options, existingData: state.data, middleware: serializedMw, maxAge }); + } + const pollWorker = async ({ url, interval = 5000, options, maxAttempts = 100, compareKeys }: PollWorkerProps) => { + let worker = workerRef.current; + dispatch({ type: 'loading', loading: true }) + worker?.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?.postMessage({ type: 'poll', url, interval, maxAttempts, options, existingData: state.data, compareKeys }); } useEffect(() => { @@ -71,6 +89,6 @@ export function useFetch() { } }, []); - return { fetchWorker, ...state! }; + return { fetchWorker, pollWorker, ...state! }; }; diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 1656d99..5b9a487 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -1,4 +1,5 @@ export * from "./state_tools"; +export * from "./poll"; export const DAY = 24 * 60 * 60 * 1000; export function cleanupWorker(worker: Worker | undefined) { diff --git a/src/lib/utils/poll.ts b/src/lib/utils/poll.ts new file mode 100644 index 0000000..c7e9266 --- /dev/null +++ b/src/lib/utils/poll.ts @@ -0,0 +1,35 @@ +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 720f6ab..9b17bd6 100644 --- a/src/lib/workers/fetch_worker.ts +++ b/src/lib/workers/fetch_worker.ts @@ -5,11 +5,19 @@ import { isMatch, dataExpired, isObject, + type UnknownDataResponseType, } from "../utils"; import type { UseStore } from "idb-keyval"; +import PollWorker from "./polling_worker.js?worker&inline"; -type ValueType = { timestamp: number, maxAge: number, data: any } +type ValueType = { timestamp: number; maxAge: number; data: any }; +type WorkerResponseType = MessageEvent< + { + type: string; + data?: UnknownDataResponseType; + } +>; const DB_NAME = "usestore-db"; const DB_STORE = "usestore-db"; @@ -17,35 +25,84 @@ const store: UseStore = createStore(DB_NAME, DB_STORE); const remove = (key: IDBValidKey) => del(key, store); const getData = (key: IDBValidKey) => get(key, store); const setData = (key: IDBValidKey, value: unknown) => set(key, value, store); -const updateData = (key: IDBValidKey, updater: (oldValue: any) => any) => update(key, updater, store) +const updateData = (key: IDBValidKey, updater: (oldValue: any) => any) => + update(key, updater, store); const handleResponse = (response: Response) => { if (!response.ok || response.status === 404) { - throw new Error( - `HTTP error! Status: ${response.status}`, - ); + throw new Error(`HTTP error! Status: ${response.status}`); } if (response.status === 403) { throw new Error(`Unauthorized!`); } return response.json(); -} +}; const handleError = (error: Error) => { self.postMessage({ type: error.message || "Unknown error", }); -} +}; self.addEventListener( "message", (event) => { 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 === "fetch") { - let { existingData, url, options, maxAge, middleware, update } = event.data; + let { + existingData, + url, + options, + maxAge, + middleware, + update, + } = event.data; const handleData = (data: unknown) => { if (middleware) { let fn = deserializeFunction(middleware); @@ -54,16 +111,23 @@ self.addEventListener( let hasChanged = !existingData || !isMatch(existingData, data); if (hasChanged) { self.postMessage({ type: "DATA", data }); - setData(url.toString(), { - data, - timestamp: Date.now(), - maxAge, - }) - .then(() => { console.info("saved data") }) - .catch(() => { console.info("couldn't access indexedDB to save data") }) + setData( + url.toString(), + { + data, + timestamp: Date.now(), + maxAge, + }, + ) + .then(() => { + console.info("saved data"); + }) + .catch(() => { + console.info("couldn't access indexedDB to save data"); + }); } self.postMessage({ type: "COMPLETE" }); - } + }; let method = methodType(options); if (method === "DELETE") { remove(url.toString()); @@ -73,63 +137,74 @@ self.addEventListener( fetch(update.url, update.options) .then(handleResponse) .then(handleData) - .catch((err) => { throw err }) + .catch((err) => { + throw err; + }); } else { self.postMessage({ type: "COMPLETE" }); } }) - .catch(handleError) + .catch(handleError); } if (method === "GET") { getData(url.toString()) - .then((value: ValueType) => { - if (!value) { - throw new Error("no value found in db"); - } - if (dataExpired(value?.maxAge, value?.timestamp)) { - remove(url.toString()); - throw new Error("data expired"); - } - self.postMessage(isMatch( - existingData, value?.data) - ?{ type: "CACHED" } - : { + .then( + (value: ValueType) => { + if (!value) { + throw new Error("no value found in db"); + } + if (dataExpired(value?.maxAge, value?.timestamp)) { + remove(url.toString()); + throw new Error("data expired"); + } + self.postMessage( + isMatch(existingData, value?.data) ? { type: "CACHED" } : { type: "PRE_LOAD", data: value?.data, - }); - }) + }, + ); + }, + ) .catch((err) => { console.info(err?.message); }); - fetch(url, options ? { ...options, signal } : { signal }) - .then(handleResponse) - .then(handleData) - .catch(handleError); + fetch(url, options ? { ...options, signal } : { signal }).then( + handleResponse, + ).then(handleData).catch(handleError); } if (method === "PUT" || method === "POST") { fetch(url, options ? { ...options, signal } : { signal }) .then(handleResponse) - .then(data => { + .then((data) => { if (update) { fetch(update.url, update.options) .then(handleResponse) .then(handleData) - .catch((err) => { throw err }) + .catch((err) => { + throw err; + }); } else { - updateData(url.toString(), (oldValue: ValueType) => { - let timestamp = Date.now(); - let newData = isObject(data) && isObject(oldValue?.data) ? { ...oldValue.data, ...data } : data; - self.postMessage({ type: method, data: newData }); - return { timestamp, maxAge, data: newData } - }) + updateData( + url.toString(), + (oldValue: ValueType) => { + let timestamp = Date.now(); + let newData = isObject(data) && isObject(oldValue?.data) ? { + ...oldValue.data, + ...data, + } : data; + self.postMessage({ type: method, data: newData }); + return { timestamp, maxAge, data: newData }; + }, + ) .catch(() => { - console.info("update store failed") + console.info("update store failed"); }) - .finally(() => {self.postMessage({ type: "COMPLETE" });}) - + .finally(() => { + self.postMessage({ type: "COMPLETE" }); + }); } }) - .catch(handleError) + .catch(handleError); } } }, diff --git a/src/lib/workers/polling_worker.ts b/src/lib/workers/polling_worker.ts new file mode 100644 index 0000000..8f1cd92 --- /dev/null +++ b/src/lib/workers/polling_worker.ts @@ -0,0 +1,35 @@ +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 From 1fbee16381fa3c11268c7c97415f10544b0448c8 Mon Sep 17 00:00:00 2001 From: Rod Lewis Date: Mon, 27 Jun 2022 16:58:01 +0800 Subject: [PATCH 2/5] build --- dist/queryPlus.umd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/queryPlus.umd.js b/dist/queryPlus.umd.js index a771541..cb9dc2e 100644 --- a/dist/queryPlus.umd.js +++ b/dist/queryPlus.umd.js @@ -1 +1 @@ -(function(e,l){typeof exports=="object"&&typeof module!="undefined"?l(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],l):(e=typeof globalThis!="undefined"?globalThis:e||self,l(e.queryPlus={},e.React))})(this,function(e,l){"use strict";var I=Object.defineProperty,k=Object.defineProperties;var C=Object.getOwnPropertyDescriptors;var G=Object.getOwnPropertySymbols;var P=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var t=(e,l,c)=>l in e?I(e,l,{enumerable:!0,configurable:!0,writable:!0,value:c}):e[l]=c,i=(e,l)=>{for(var c in l||(l={}))P.call(l,c)&&t(e,c,l[c]);if(G)for(var c of G(l))J.call(l,c)&&t(e,c,l[c]);return e},b=(e,l)=>k(e,C(l));const c="dmFyIGI9T2JqZWN0LmRlZmluZVByb3BlcnR5LEk9T2JqZWN0LmRlZmluZVByb3BlcnRpZXM7dmFyIFE9T2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcnM7dmFyIEw9T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tzaWduYWw6cn0pOntzaWduYWw6cn0pLnRoZW4oQSkudGhlbihzPT57cD9mZXRjaChwLnVybCxwLm9wdGlvbnMpLnRoZW4oQSkudGhlbihTKS5jYXRjaChoPT57dGhyb3cgaH0pOiQoby50b1N0cmluZygpLGg9PntsZXQgQj1EYXRlLm5vdygpLHg9RShzKSYmRShoPT1udWxsP3ZvaWQgMDpoLmRhdGEpP2coZyh7fSxoLmRhdGEpLHMpOnM7cmV0dXJuIHNlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6dSxkYXRhOnh9KSx7dGltZXN0YW1wOkIsbWF4QWdlOkMsZGF0YTp4fX0pLmNhdGNoKCgpPT57Y29uc29sZS5pbmZvKCJ1cGRhdGUgc3RvcmUgZmFpbGVkIil9KS5maW5hbGx5KCgpPT57c2VsZi5wb3N0TWVzc2FnZSh7dHlwZToiQ09NUExFVEUifSl9KX0pLmNhdGNoKEQpfX0pfSkoKTsK",n=typeof window!="undefined"&&window.Blob&&new Blob([atob(c)],{type:"text/javascript;charset=utf-8"});function y(){const d=n&&(window.URL||window.webkitURL).createObjectURL(n);try{return d?new Worker(d,{}):new Worker("data:application/javascript;base64,"+c,{type:"module"})}finally{d&&(window.URL||window.webkitURL).revokeObjectURL(d)}}const K={data:void 0,error:void 0,loading:!1,preload:!1,update:!0};function Y(d,Z){switch(Z.type){case"pre-load":return b(i({},d),{data:Z.data,loading:!1,preload:!0,error:void 0});case"data":return b(i({},d),{data:Z.data,loading:!1,preload:!1,error:void 0});case"error":return b(i({},d),{error:Z.error,loading:!1,preload:!1});case"loading":return b(i({},d),{loading:Z.loading});default:return d}}const s=24*60*60*1e3;function h(d){d==null||d.postMessage({type:"cancel"}),d==null||d.terminate(),d=void 0}const R=d=>encodeURI(d.toString());function X(){const[d,Z]=l.useReducer(Y,K),m=l.useRef(),L=async({url:S,fetchOptions:W,maxAge:T=s,middleware:o})=>{let p=m.current;Z({type:"loading",loading:!0}),p==null||p.addEventListener("message",({data:{type:u,data:a}})=>{switch(u){case"CACHED":case"COMPLETE":Z({type:"loading",loading:!1});break;case"DATA":Z({type:"data",data:a});break;case"PRE_LOAD":Z({type:"pre-load",data:a});break;default:Z({type:"error",error:new Error(u)});break}});let V=o?R(o):void 0;p==null||p.postMessage({type:"fetch",url:S,fetchOptions:W,existingData:d.data,middleware:V,maxAge:T})};return l.useEffect(()=>(m.current=new y,()=>{h(m.current)}),[]),i({fetchWorker:L},d)}e.useFetch=X,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); +(function(Z,d){typeof exports=="object"&&typeof module!="undefined"?d(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],d):(Z=typeof globalThis!="undefined"?globalThis:Z||self,d(Z.queryPlus={},Z.React))})(this,function(Z,d){"use strict";var u=Object.defineProperty,K=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable;var t=(Z,d,a)=>d in Z?u(Z,d,{enumerable:!0,configurable:!0,writable:!0,value:a}):Z[d]=a,p=(Z,d)=>{for(var a in d||(d={}))y.call(d,a)&&t(Z,a,d[a]);if(U)for(var a of U(d))L.call(d,a)&&t(Z,a,d[a]);return Z},m=(Z,d)=>K(Z,H(d));const a="dmFyIGs9T2JqZWN0LmRlZmluZVByb3BlcnR5LGo9T2JqZWN0LmRlZmluZVByb3BlcnRpZXM7dmFyIEE9T2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcnM7dmFyIFc9T2JqZWN0LmdldE93blByb3BlcnR5U3ltYm9sczt2YXIgUT1PYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LHY9T2JqZWN0LnByb3RvdHlwZS5wcm9wZXJ0eUlzRW51bWVyYWJsZTt2YXIgQj0ocixhLGwpPT5hIGluIHI/ayhyLGEse2VudW1lcmFibGU6ITAsY29uZmlndXJhYmxlOiEwLHdyaXRhYmxlOiEwLHZhbHVlOmx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5jYXRjaChzPT57Y29uc29sZS5pbmZvKHM9PW51bGw/dm9pZCAwOnMubWVzc2FnZSl9KSxmZXRjaChpLGg/RyhmKHt9LGgpLHtzaWduYWw6Y30pOntzaWduYWw6Y30pLnRoZW4oeSkudGhlbihwKS5jYXRjaChSKSksKFo9PT0iUFVUInx8Wj09PSJQT1NUIikmJmZldGNoKGksaD9HKGYoe30saCkse3NpZ25hbDpjfSk6e3NpZ25hbDpjfSkudGhlbih5KS50aGVuKHM9PnttP2ZldGNoKG0udXJsLG0ub3B0aW9ucykudGhlbih5KS50aGVuKHApLmNhdGNoKGI9Pnt0aHJvdyBifSk6VihpLnRvU3RyaW5nKCksYj0+e2xldCBFPURhdGUubm93KCksSD1TKHMpJiZTKGI9PW51bGw/dm9pZCAwOmIuZGF0YSk/ZihmKHt9LGIuZGF0YSkscyk6cztyZXR1cm4gc2VsZi5wb3N0TWVzc2FnZSh7dHlwZTpaLGRhdGE6SH0pLHt0aW1lc3RhbXA6RSxtYXhBZ2U6VCxkYXRhOkh9fSkuY2F0Y2goKCk9Pntjb25zb2xlLmluZm8oInVwZGF0ZSBzdG9yZSBmYWlsZWQiKX0pLmZpbmFsbHkoKCk9PntzZWxmLnBvc3RNZXNzYWdlKHt0eXBlOiJDT01QTEVURSJ9KX0pfSkuY2F0Y2goUil9fSl9KSgpOwo=",N=typeof window!="undefined"&&window.Blob&&new Blob([atob(a)],{type:"text/javascript;charset=utf-8"});function o(){const l=N&&(window.URL||window.webkitURL).createObjectURL(N);try{return l?new Worker(l,{}):new Worker("data:application/javascript;base64,"+a,{type:"module"})}finally{l&&(window.URL||window.webkitURL).revokeObjectURL(l)}}const S={data:void 0,error:void 0,loading:!1,preload:!1,update:!0};function h(l,W){switch(W.type){case"pre-load":return m(p({},l),{data:W.data,loading:!1,preload:!0,error:void 0});case"data":return m(p({},l),{data:W.data,loading:!1,preload:!1,error:void 0});case"error":return m(p({},l),{error:W.error,loading:!1,preload:!1});case"loading":return m(p({},l),{loading:W.loading});default:return l}}const s=24*60*60*1e3;function J(l){l==null||l.postMessage({type:"cancel"}),l==null||l.terminate(),l=void 0}const F=l=>encodeURI(l.toString());function X(){const[l,W]=d.useReducer(h,S),e=d.useRef(),T=async({url:R,options:n,maxAge:i=s,middleware:G})=>{let V=e.current;W({type:"loading",loading:!0}),V==null||V.addEventListener("message",({data:{type:c,data:Y}})=>{switch(c){case"CACHED":case"COMPLETE":W({type:"loading",loading:!1});break;case"DATA":W({type:"data",data:Y});break;case"PRE_LOAD":W({type:"pre-load",data:Y});break;default:W({type:"error",error:new Error(c)});break}});let b=G?F(G):void 0;V==null||V.postMessage({type:"fetch",url:R,options:n,existingData:l.data,middleware:b,maxAge:i})},k=async({url:R,interval:n=5e3,options:i,maxAttempts:G=100,compareKeys:V})=>{let b=e.current;W({type:"loading",loading:!0}),b==null||b.addEventListener("message",({data:{type:c,data:Y}})=>{W(c==="COMPLETE"?{type:"loading",loading:!1}:c==="DATA"?{type:"data",data:Y}:{type:"error",error:new Error(c)})}),b==null||b.postMessage({type:"poll",url:R,interval:n,maxAttempts:G,options:i,existingData:l.data,compareKeys:V})};return d.useEffect(()=>(e.current=new o,()=>{J(e.current)}),[]),p({fetchWorker:T,pollWorker:k},l)}Z.useFetch=X,Object.defineProperties(Z,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); From 3c242317480aa1ae988b1356a571b4cf4f13a5fb Mon Sep 17 00:00:00 2001 From: Rod Lewis Date: Mon, 27 Jun 2022 19:41:18 +0800 Subject: [PATCH 3/5] add more hooks --- dist/lib/hooks/useFetch.d.ts | 37 ++------------- dist/lib/hooks/usePoll.d.ts | 20 +++++++++ dist/lib/hooks/usePreFetch.d.ts | 2 + dist/lib/index.d.ts | 2 + dist/lib/types.d.ts | 39 ++++++++++++++++ dist/lib/utils/index.d.ts | 7 ++- dist/lib/utils/store_tools.d.ts | 6 +++ dist/queryPlus.es.js | 78 +++++++++++++++++++------------- dist/queryPlus.umd.js | 2 +- src/lib/hooks/useFetch.tsx | 59 +++--------------------- src/lib/hooks/usePoll.tsx | 26 +++++++++++ src/lib/hooks/usePreFetch.tsx | 24 ++++++++++ src/lib/hooks/useStore.tsx | 19 ++++++++ src/lib/index.ts | 4 +- src/lib/types.d.ts | 39 ++++++++++++++++ src/lib/utils/index.ts | 10 +++-- src/lib/utils/store_tools.ts | 20 +++++++++ src/lib/workers/fetch_worker.ts | 48 ++++++++++++-------- src/lib/workers/store_worker.ts | 79 +++++++++++++++++++++++++++++++++ 19 files changed, 375 insertions(+), 146 deletions(-) create mode 100644 dist/lib/hooks/usePoll.d.ts create mode 100644 dist/lib/hooks/usePreFetch.d.ts create mode 100644 dist/lib/types.d.ts create mode 100644 dist/lib/utils/store_tools.d.ts create mode 100644 src/lib/hooks/usePoll.tsx create mode 100644 src/lib/hooks/usePreFetch.tsx create mode 100644 src/lib/hooks/useStore.tsx create mode 100644 src/lib/types.d.ts create mode 100644 src/lib/utils/store_tools.ts create mode 100644 src/lib/workers/store_worker.ts diff --git a/dist/lib/hooks/useFetch.d.ts b/dist/lib/hooks/useFetch.d.ts index 3f402bb..9449fdc 100644 --- a/dist/lib/hooks/useFetch.d.ts +++ b/dist/lib/hooks/useFetch.d.ts @@ -1,32 +1,4 @@ -import { UnknownDataResponseType } from "../utils"; -export interface FetchWorkerProps { - options?: RequestInit | undefined; - maxAge?: number; - middleware?: (data: UnknownDataResponseType) => UnknownDataResponseType; - url: RequestInfo | URL; - update?: { - url: RequestInfo | URL; - options?: RequestInit | undefined; - }; -} -export interface PollWorkerProps { - url: RequestInfo | URL; - interval: number; - options?: RequestInit | undefined; - maxAttempts?: number; - existingData?: number; - compareKeys?: string[]; -} -/** - * useFetch is a React hook that can be initialized with no params. - * @example const { data, error, loading, fetchWorker } = useFetch() - * fetchWorker({ - * url: 'https://swapi.dev/api/people/1/', - * middleware: (d:Record) => { let keys = Object.keys(d); return {[keys[0]]: d[keys[0]], [keys[1]]: d[keys[1]]}} - * }); - * - * - */ +import type { FetchWorkerProps } from "../types"; export declare function useFetch(): { data: any; loading: boolean; @@ -34,21 +6,18 @@ export declare function useFetch(): { error: undefined; update: boolean; fetchWorker: ({ url, options, maxAge, middleware }: FetchWorkerProps) => Promise; - pollWorker: ({ url, interval, options, maxAttempts, compareKeys }: PollWorkerProps) => Promise; } | { error: any; loading: boolean; preload: boolean; - data: UnknownDataResponseType; + data: import("../utils").UnknownDataResponseType; update: boolean; fetchWorker: ({ url, options, maxAge, middleware }: FetchWorkerProps) => Promise; - pollWorker: ({ url, interval, options, maxAttempts, compareKeys }: PollWorkerProps) => Promise; } | { loading: any; - data: UnknownDataResponseType; + data: import("../utils").UnknownDataResponseType; error?: Error | undefined; preload: boolean; update: boolean; fetchWorker: ({ url, options, maxAge, middleware }: FetchWorkerProps) => Promise; - pollWorker: ({ url, interval, options, maxAttempts, compareKeys }: PollWorkerProps) => Promise; }; diff --git a/dist/lib/hooks/usePoll.d.ts b/dist/lib/hooks/usePoll.d.ts new file mode 100644 index 0000000..c29767e --- /dev/null +++ b/dist/lib/hooks/usePoll.d.ts @@ -0,0 +1,20 @@ +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/hooks/usePreFetch.d.ts b/dist/lib/hooks/usePreFetch.d.ts new file mode 100644 index 0000000..4bf89b2 --- /dev/null +++ b/dist/lib/hooks/usePreFetch.d.ts @@ -0,0 +1,2 @@ +import type { FetchWorkerBaseRequestType } from "../types"; +export declare function usePreFetch(prefetch?: Array): void; diff --git a/dist/lib/index.d.ts b/dist/lib/index.d.ts index e54a83f..9d1c0df 100644 --- a/dist/lib/index.d.ts +++ b/dist/lib/index.d.ts @@ -1 +1,3 @@ export { useFetch } from './hooks/useFetch'; +export { usePoll } from './hooks/usePoll'; +export { usePreFetch } from './hooks/usePreFetch'; diff --git a/dist/lib/types.d.ts b/dist/lib/types.d.ts new file mode 100644 index 0000000..f87e456 --- /dev/null +++ b/dist/lib/types.d.ts @@ -0,0 +1,39 @@ +export type StringAnyTuple = [string, any] +export type ArrayOfStringAnyTuple = Array +export type createArrayOfUpdatesType = (oldRecord: Record, newRecord: Record) => ArrayOfStringAnyTuple + +export type WorkerResponseType = MessageEvent<{ + type: string; + data?: UnknownDataResponseType +}> +export interface FetchWorkerBaseRequestType { + options?: RequestInit | undefined + maxAge?: number + middleware?: (data: UnknownDataResponseType) => UnknownDataResponseType + url: RequestInfo | URL +} + +export interface FetchWorkerProps extends FetchWorkerBaseRequestType { + /* + update will be fetched after the response is received. + This is useful for updating after POST PUT or DELETE, + where the api doesn't return all the data and the GET + endpoint is different. + */ + update?: { + url: RequestInfo | URL, + options?: RequestInit | undefined + } +} +export interface PollWorkerProps { + url: RequestInfo | URL + interval: number, + options?: RequestInit | undefined + maxAttempts?: number, + existingData?: number, + compareKeys?: string[] +} + +export type ValueType = { timestamp: number; maxAge: number; data: any }; + + diff --git a/dist/lib/utils/index.d.ts b/dist/lib/utils/index.d.ts index 9a8a5bb..e8d32f0 100644 --- a/dist/lib/utils/index.d.ts +++ b/dist/lib/utils/index.d.ts @@ -1,4 +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; @@ -8,9 +10,6 @@ export declare const flattenObjectToArray: (obj: Record, parent?: s export declare const flattenAndSortArray: (arr: Array) => any[]; export declare const methodType: (options: RequestInit | undefined) => string; export declare const isMatch: (a: unknown, b: unknown, compareKeys?: string[] | undefined) => boolean; -export declare type StringAnyTuple = [string, any]; -export declare type ArrayOfStringAnyTuple = Array; -export declare type createArrayOfUpdatesType = (oldRecord: Record, newRecord: Record) => ArrayOfStringAnyTuple; export declare const createArrayOfUpdates: createArrayOfUpdatesType; -export declare const serializeFunction: (f: Function) => string; +export declare const serializeFunction: (f?: Function | undefined) => string | undefined; export declare const deserializeFunction: (s: string) => any; diff --git a/dist/lib/utils/store_tools.d.ts b/dist/lib/utils/store_tools.d.ts new file mode 100644 index 0000000..3f122dd --- /dev/null +++ b/dist/lib/utils/store_tools.d.ts @@ -0,0 +1,6 @@ +export declare function store(): { + remove: (key: IDBValidKey) => Promise; + getData: (key: IDBValidKey) => Promise; + setData: (key: IDBValidKey, value: unknown) => Promise; + updateData: (key: IDBValidKey, updater: (oldValue: any) => any) => Promise; +}; diff --git a/dist/queryPlus.es.js b/dist/queryPlus.es.js index 5fdcc86..205ba7c 100644 --- a/dist/queryPlus.es.js +++ b/dist/queryPlus.es.js @@ -18,7 +18,8 @@ var __spreadValues = (a, b) => { }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); import { useReducer, useRef, useEffect } from "react"; -const encodedJs = "dmFyIGs9T2JqZWN0LmRlZmluZVByb3BlcnR5LGo9T2JqZWN0LmRlZmluZVByb3BlcnRpZXM7dmFyIEE9T2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcnM7dmFyIFc9T2JqZWN0LmdldE93blByb3BlcnR5U3ltYm9sczt2YXIgUT1PYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LHY9T2JqZWN0LnByb3RvdHlwZS5wcm9wZXJ0eUlzRW51bWVyYWJsZTt2YXIgQj0ocixhLGwpPT5hIGluIHI/ayhyLGEse2VudW1lcmFibGU6ITAsY29uZmlndXJhYmxlOiEwLHdyaXRhYmxlOiEwLHZhbHVlOmx9KTpyW2FdPWwsZj0ocixhKT0+e2Zvcih2YXIgbCBpbiBhfHwoYT17fSkpUS5jYWxsKGEsbCkmJkIocixsLGFbbF0pO2lmKFcpZm9yKHZhciBsIG9mIFcoYSkpdi5jYWxsKGEsbCkmJkIocixsLGFbbF0pO3JldHVybiByfSxHPShyLGEpP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Om87cmV0dXJuIHNlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6UyxkYXRhOld9KSx7dGltZXN0YW1wOkgsbWF4QWdlOnAsZGF0YTpXfX0pLmNhdGNoKCgpPT57Y29uc29sZS5pbmZvKCJ1cGRhdGUgc3RvcmUgZmFpbGVkIil9KS5maW5hbGx5KCgpPT57c2VsZi5wb3N0TWVzc2FnZSh7dHlwZToiQ09NUExFVEUifSl9KX0pLmNhdGNoKFkpfX0pfSkoKTsK"; 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); @@ -55,7 +56,7 @@ function cleanupWorker(worker) { worker == null ? void 0 : worker.terminate(); worker = void 0; } -const serializeFunction = (f) => encodeURI(f.toString()); +const serializeFunction = (f) => f ? encodeURI(f.toString()) : void 0; function useFetch() { const [state, dispatch] = useReducer(reducer, initialState); const workerRef = useRef(); @@ -104,29 +105,35 @@ function useFetch() { break; } }); - let serializedMw = middleware ? serializeFunction(middleware) : void 0; worker == null ? void 0 : worker.postMessage({ type: "fetch", url, options, existingData: state.data, - middleware: serializedMw, + middleware: serializeFunction(middleware), maxAge }); }; - const pollWorker = async ({ - url, - interval = 5e3, - options, - maxAttempts = 100, - compareKeys - }) => { - let worker = workerRef.current; + useEffect(() => { + workerRef.current = new WorkerWrapper(); + return () => { + cleanupWorker(workerRef.current); + }; + }, []); + return __spreadValues({ + fetchWorker + }, state); +} +function usePoll(props) { + var _a, _b; + const [state, dispatch] = useReducer(reducer, initialState); + const worker = useRef(new WorkerWrapper()); + if (props && worker.current) { dispatch({ type: "loading", loading: true }); - worker == null ? void 0 : worker.addEventListener("message", ({ + (_a = worker.current) == null ? void 0 : _a.addEventListener("message", ({ data: { type, data @@ -148,25 +155,36 @@ function useFetch() { error: new Error(type) }); }); - worker == null ? void 0 : worker.postMessage({ - type: "poll", - url, - interval, - maxAttempts, - options, - existingData: state.data, - compareKeys - }); - }; + (_b = worker.current) == null ? void 0 : _b.postMessage(__spreadProps(__spreadValues({ + type: "poll" + }, props), { + existingData: state.data + })); + } useEffect(() => { - workerRef.current = new WorkerWrapper(); return () => { - cleanupWorker(workerRef.current); + cleanupWorker(worker.current); + }; + }, []); + return __spreadValues({}, state); +} +function usePreFetch(prefetch) { + const worker = useRef(new WorkerWrapper()); + useEffect(() => { + var _a; + if (prefetch && worker.current) { + (_a = worker.current) == null ? void 0 : _a.postMessage({ + type: "pre-fetch", + prefetch: prefetch.map((p) => __spreadProps(__spreadValues({}, p), { + middleware: serializeFunction(p.middleware) + })) + }); + } + }, [prefetch, worker.current]); + useEffect(() => { + return () => { + cleanupWorker(worker.current); }; }, []); - return __spreadValues({ - fetchWorker, - pollWorker - }, state); } -export { useFetch }; +export { useFetch, usePoll, usePreFetch }; diff --git a/dist/queryPlus.umd.js b/dist/queryPlus.umd.js index cb9dc2e..679c803 100644 --- a/dist/queryPlus.umd.js +++ b/dist/queryPlus.umd.js @@ -1 +1 @@ -(function(Z,d){typeof exports=="object"&&typeof module!="undefined"?d(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],d):(Z=typeof globalThis!="undefined"?globalThis:Z||self,d(Z.queryPlus={},Z.React))})(this,function(Z,d){"use strict";var u=Object.defineProperty,K=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable;var t=(Z,d,a)=>d in Z?u(Z,d,{enumerable:!0,configurable:!0,writable:!0,value:a}):Z[d]=a,p=(Z,d)=>{for(var a in d||(d={}))y.call(d,a)&&t(Z,a,d[a]);if(U)for(var a of U(d))L.call(d,a)&&t(Z,a,d[a]);return Z},m=(Z,d)=>K(Z,H(d));const a="dmFyIGs9T2JqZWN0LmRlZmluZVByb3BlcnR5LGo9T2JqZWN0LmRlZmluZVByb3BlcnRpZXM7dmFyIEE9T2JqZWN0LmdldE93blByb3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w/dm9pZCAwOnMubWF4QWdlLHM9PW51bGw/dm9pZCAwOnMudGltZXN0YW1wKSl0aHJvdyBJKGkudG9TdHJpbmcoKSksbmV3IEVycm9yKCJkYXRhIGV4cGlyZWQiKTtzZWxmLnBvc3RNZXNzYWdlKFgoZCxzPT1udWxsP3ZvaWQgMDpzLmRhdGEpP3t0eXBlOiJDQUNIRUQifTp7dHlwZToiUFJFX0xPQUQiLGRhdGE6cz09bnVsbD92b2lkIDA6cy5kYXRhfSl9KS5jYXRjaChzPT57Y29uc29sZS5pbmZvKHM9PW51bGw/dm9pZCAwOnMubWVzc2FnZSl9KSxmZXRjaChpLGg/RyhmKHt9LGgpLHtzaWduYWw6Y30pOntzaWduYWw6Y30pLnRoZW4oeSkudGhlbihwKS5jYXRjaChSKSksKFo9PT0iUFVUInx8Wj09PSJQT1NUIikmJmZldGNoKGksaD9HKGYoe30saCkse3NpZ25hbDpjfSk6e3NpZ25hbDpjfSkudGhlbih5KS50aGVuKHM9PnttP2ZldGNoKG0udXJsLG0ub3B0aW9ucykudGhlbih5KS50aGVuKHApLmNhdGNoKGI9Pnt0aHJvdyBifSk6VihpLnRvU3RyaW5nKCksYj0+e2xldCBFPURhdGUubm93KCksSD1TKHMpJiZTKGI9PW51bGw/dm9pZCAwOmIuZGF0YSk/ZihmKHt9LGIuZGF0YSkscyk6cztyZXR1cm4gc2VsZi5wb3N0TWVzc2FnZSh7dHlwZTpaLGRhdGE6SH0pLHt0aW1lc3RhbXA6RSxtYXhBZ2U6VCxkYXRhOkh9fSkuY2F0Y2goKCk9Pntjb25zb2xlLmluZm8oInVwZGF0ZSBzdG9yZSBmYWlsZWQiKX0pLmZpbmFsbHkoKCk9PntzZWxmLnBvc3RNZXNzYWdlKHt0eXBlOiJDT01QTEVURSJ9KX0pfSkuY2F0Y2goUil9fSl9KSgpOwo=",N=typeof window!="undefined"&&window.Blob&&new Blob([atob(a)],{type:"text/javascript;charset=utf-8"});function o(){const l=N&&(window.URL||window.webkitURL).createObjectURL(N);try{return l?new Worker(l,{}):new Worker("data:application/javascript;base64,"+a,{type:"module"})}finally{l&&(window.URL||window.webkitURL).revokeObjectURL(l)}}const S={data:void 0,error:void 0,loading:!1,preload:!1,update:!0};function h(l,W){switch(W.type){case"pre-load":return m(p({},l),{data:W.data,loading:!1,preload:!0,error:void 0});case"data":return m(p({},l),{data:W.data,loading:!1,preload:!1,error:void 0});case"error":return m(p({},l),{error:W.error,loading:!1,preload:!1});case"loading":return m(p({},l),{loading:W.loading});default:return l}}const s=24*60*60*1e3;function J(l){l==null||l.postMessage({type:"cancel"}),l==null||l.terminate(),l=void 0}const F=l=>encodeURI(l.toString());function X(){const[l,W]=d.useReducer(h,S),e=d.useRef(),T=async({url:R,options:n,maxAge:i=s,middleware:G})=>{let V=e.current;W({type:"loading",loading:!0}),V==null||V.addEventListener("message",({data:{type:c,data:Y}})=>{switch(c){case"CACHED":case"COMPLETE":W({type:"loading",loading:!1});break;case"DATA":W({type:"data",data:Y});break;case"PRE_LOAD":W({type:"pre-load",data:Y});break;default:W({type:"error",error:new Error(c)});break}});let b=G?F(G):void 0;V==null||V.postMessage({type:"fetch",url:R,options:n,existingData:l.data,middleware:b,maxAge:i})},k=async({url:R,interval:n=5e3,options:i,maxAttempts:G=100,compareKeys:V})=>{let b=e.current;W({type:"loading",loading:!0}),b==null||b.addEventListener("message",({data:{type:c,data:Y}})=>{W(c==="COMPLETE"?{type:"loading",loading:!1}:c==="DATA"?{type:"data",data:Y}:{type:"error",error:new Error(c)})}),b==null||b.postMessage({type:"poll",url:R,interval:n,maxAttempts:G,options:i,existingData:l.data,compareKeys:V})};return d.useEffect(()=>(e.current=new o,()=>{J(e.current)}),[]),p({fetchWorker:T,pollWorker:k},l)}Z.useFetch=X,Object.defineProperties(Z,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); +(function(Z,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):(Z=typeof globalThis!="undefined"?globalThis:Z||self,d(Z.queryPlus={},Z.React))})(this,function(Z,d){"use strict";var F=Object.defineProperty,y=Object.defineProperties;var J=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var x=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var X=(Z,d,W)=>d in Z?F(Z,d,{enumerable:!0,configurable:!0,writable:!0,value:W}):Z[d]=W,G=(Z,d)=>{for(var W in d||(d={}))x.call(d,W)&&X(Z,W,d[W]);if(S)for(var W of S(d))I.call(d,W)&&X(Z,W,d[W]);return Z},c=(Z,d)=>y(Z,J(d));const W="dmFyIGs9T2JqZWN0LmRlZmluZVByb3BlcnR5LEE9T2JqZWN0LmRlZmluZVByb3BlcnRpZXM7dmFyIGo9T2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcnM7dmFyIEI9T2JqZWN0LmdldE93blByb3BlcnR5U3ltYm9sczt2YXIgUT1PYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LHY9T2JqZWN0LnByb3RvdHlwZS5wcm9wZXJ0eUlzRW51bWVyYWJsZTt2YXIgRD0oaCxkLGwpPT5kIGluIGg/ayhoLGQse2VudW1lcmFibGU6ITAsY29uZmlndXJhYmxlOiEwLHdyaXRhYmxlOiEwLHZhbHVlOmx9KTpoW2RdPWwseT0oaCxkKT0+e2Zvcih2YXIgbCBpbiBkfHwoZD17fSkpUS5jYWxsKGQsbCkmJkQoaCxsLGRbbF0pO2lmKEIpZm9yKHZhciBsIG9mIEIoZCkpdi5jYWxsKGQsbCkmJkQoaCxsLGRbbF0pO3JldHVybiBofSxUPShoLGQpPT5BKGgsaihkKSk7KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2Z1bmN0aW9uIGgodCl7cmV0dXJuIG5ldyBQcm9taXNlKChlLG4pPT57dC5vbmNvbXBsZXRlPXQub25zdWNjZXNzPSgpPT5lKHQucmVzdWx0KSx0Lm9uYWJvcnQ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iQ09NUExFVEUifSl9KX0pLmNhdGNoKFkpfX0pfSkoKTsK",h=typeof window!="undefined"&&window.Blob&&new Blob([atob(W)],{type:"text/javascript;charset=utf-8"});function a(){const l=h&&(window.URL||window.webkitURL).createObjectURL(h);try{return l?new Worker(l,{}):new Worker("data:application/javascript;base64,"+W,{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 t(l,b){switch(b.type){case"pre-load":return c(G({},l),{data:b.data,loading:!1,preload:!0,error:void 0});case"data":return c(G({},l),{data:b.data,loading:!1,preload:!1,error:void 0});case"error":return c(G({},l),{error:b.error,loading:!1,preload:!1});case"loading":return c(G({},l),{loading:b.loading});default:return l}}const k=24*60*60*1e3;function i(l){l==null||l.postMessage({type:"cancel"}),l==null||l.terminate(),l=void 0}const u=l=>l?encodeURI(l.toString()):void 0;function N(){const[l,b]=d.useReducer(t,T),p=d.useRef(),e=async({url:n,options:Y,maxAge:m=k,middleware:R})=>{let V=p.current;b({type:"loading",loading:!0}),V==null||V.addEventListener("message",({data:{type:o,data:U}})=>{switch(o){case"CACHED":case"COMPLETE":b({type:"loading",loading:!1});break;case"DATA":b({type:"data",data:U});break;case"PRE_LOAD":b({type:"pre-load",data:U});break;default:b({type:"error",error:new Error(o)});break}}),V==null||V.postMessage({type:"fetch",url:n,options:Y,existingData:l.data,middleware:u(R),maxAge:m})};return d.useEffect(()=>(p.current=new a,()=>{i(p.current)}),[]),G({fetchWorker:e},l)}function s(l){var n,Y;const[b,p]=d.useReducer(t,T),e=d.useRef(new a);return l&&e.current&&(p({type:"loading",loading:!0}),(n=e.current)==null||n.addEventListener("message",({data:{type:m,data:R}})=>{p(m==="COMPLETE"?{type:"loading",loading:!1}:m==="DATA"?{type:"data",data:R}:{type:"error",error:new Error(m)})}),(Y=e.current)==null||Y.postMessage(c(G({type:"poll"},l),{existingData:b.data}))),d.useEffect(()=>()=>{i(e.current)},[]),G({},b)}function K(l){const b=d.useRef(new a);d.useEffect(()=>{var p;l&&b.current&&((p=b.current)==null||p.postMessage({type:"pre-fetch",prefetch:l.map(e=>c(G({},e),{middleware:u(e.middleware)}))}))},[l,b.current]),d.useEffect(()=>()=>{i(b.current)},[])}Z.useFetch=N,Z.usePoll=s,Z.usePreFetch=K,Object.defineProperties(Z,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); diff --git a/src/lib/hooks/useFetch.tsx b/src/lib/hooks/useFetch.tsx index e467b1e..ca4ee6a 100644 --- a/src/lib/hooks/useFetch.tsx +++ b/src/lib/hooks/useFetch.tsx @@ -1,56 +1,17 @@ import { useRef, useEffect, useReducer } from "react"; import FetchWorker from '../workers/fetch_worker.js?worker&inline' -import { cleanupWorker, DAY, initialState, reducer, serializeFunction, UnknownDataResponseType } from "../utils"; +import { cleanupWorker, DAY, initialState, reducer, serializeFunction } from "../utils"; +import type { FetchWorkerProps, WorkerResponseType } from "../types"; -type WorkerResponseType = MessageEvent<{ - type: string; - data?: UnknownDataResponseType -}> -export interface FetchWorkerProps { - options?: RequestInit | undefined - maxAge?: number - middleware?: (data: UnknownDataResponseType) => UnknownDataResponseType - url: RequestInfo | URL - /* - update will be fetched after the response is received. - This is useful for updating after POST PUT or DELETE, - where the api doesn't return all the data and the GET - endpoint is different. - */ - update?: { - url: RequestInfo | URL, - options?: RequestInit | undefined - } -} -export interface PollWorkerProps { - url: RequestInfo | URL - interval: number, - options?: RequestInit | undefined - maxAttempts?: number, - existingData?: number, - compareKeys?: string[] -} -/** - * useFetch is a React hook that can be initialized with no params. - * @example const { data, error, loading, fetchWorker } = useFetch() - * fetchWorker({ - * url: 'https://swapi.dev/api/people/1/', - * middleware: (d:Record) => { let keys = Object.keys(d); return {[keys[0]]: d[keys[0]], [keys[1]]: d[keys[1]]}} - * }); - * - * - */ export function useFetch() { const [state, dispatch] = useReducer(reducer, initialState); const workerRef = useRef(); - const fetchWorker = async ({ url, options, maxAge = DAY, middleware }: FetchWorkerProps) => { let worker = workerRef.current; dispatch({ type: 'loading', loading: true }); - worker?.addEventListener('message', ({ data: { type, data } }: WorkerResponseType) => { switch (type) { case 'CACHED': @@ -68,18 +29,8 @@ export function useFetch() { break; } }); - let serializedMw = middleware ? serializeFunction(middleware) : undefined - worker?.postMessage({ type: 'fetch', url, options, existingData: state.data, middleware: serializedMw, maxAge }); - } - const pollWorker = async ({ url, interval = 5000, options, maxAttempts = 100, compareKeys }: PollWorkerProps) => { - let worker = workerRef.current; - dispatch({ type: 'loading', loading: true }) - worker?.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?.postMessage({ type: 'poll', url, interval, maxAttempts, options, existingData: state.data, compareKeys }); + + worker?.postMessage({ type: 'fetch', url, options, existingData: state.data, middleware: serializeFunction(middleware), maxAge }); } useEffect(() => { @@ -89,6 +40,6 @@ export function useFetch() { } }, []); - return { fetchWorker, pollWorker, ...state! }; + return { fetchWorker, ...state! }; }; diff --git a/src/lib/hooks/usePoll.tsx b/src/lib/hooks/usePoll.tsx new file mode 100644 index 0000000..7e44f2f --- /dev/null +++ b/src/lib/hooks/usePoll.tsx @@ -0,0 +1,26 @@ +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()); + 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 }); + } + useEffect(() => { + return () => { + cleanupWorker(worker.current); + } + }, []); + return { ...state! }; +}; diff --git a/src/lib/hooks/usePreFetch.tsx b/src/lib/hooks/usePreFetch.tsx new file mode 100644 index 0000000..223a720 --- /dev/null +++ b/src/lib/hooks/usePreFetch.tsx @@ -0,0 +1,24 @@ +import { useRef, useEffect } from "react"; + +import FetchWorker from '../workers/fetch_worker.js?worker&inline' +import { cleanupWorker, serializeFunction } from "../utils"; + +import type { FetchWorkerBaseRequestType } from "../types"; + + +export function usePreFetch(prefetch?: Array) { + const worker = useRef(new FetchWorker()); + useEffect(() => { + if(prefetch && worker.current) { + worker.current?.postMessage({ type: 'pre-fetch', prefetch: prefetch.map(p => ({...p, middleware: serializeFunction(p.middleware)})) }); + } + }, [prefetch, worker.current]); + + useEffect(() => { + // worker.current = new FetchWorker() + return () => { + cleanupWorker(worker.current); + } + }, []); +}; + diff --git a/src/lib/hooks/useStore.tsx b/src/lib/hooks/useStore.tsx new file mode 100644 index 0000000..c2743ce --- /dev/null +++ b/src/lib/hooks/useStore.tsx @@ -0,0 +1,19 @@ +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 546d122..3128e79 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1 +1,3 @@ -export {useFetch} from './hooks/useFetch'; \ No newline at end of file +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/types.d.ts b/src/lib/types.d.ts new file mode 100644 index 0000000..f87e456 --- /dev/null +++ b/src/lib/types.d.ts @@ -0,0 +1,39 @@ +export type StringAnyTuple = [string, any] +export type ArrayOfStringAnyTuple = Array +export type createArrayOfUpdatesType = (oldRecord: Record, newRecord: Record) => ArrayOfStringAnyTuple + +export type WorkerResponseType = MessageEvent<{ + type: string; + data?: UnknownDataResponseType +}> +export interface FetchWorkerBaseRequestType { + options?: RequestInit | undefined + maxAge?: number + middleware?: (data: UnknownDataResponseType) => UnknownDataResponseType + url: RequestInfo | URL +} + +export interface FetchWorkerProps extends FetchWorkerBaseRequestType { + /* + update will be fetched after the response is received. + This is useful for updating after POST PUT or DELETE, + where the api doesn't return all the data and the GET + endpoint is different. + */ + update?: { + url: RequestInfo | URL, + options?: RequestInit | undefined + } +} +export interface PollWorkerProps { + url: RequestInfo | URL + interval: number, + options?: RequestInit | undefined + maxAttempts?: number, + existingData?: number, + compareKeys?: string[] +} + +export type ValueType = { timestamp: number; maxAge: number; data: any }; + + diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 5b9a487..1937155 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -1,5 +1,9 @@ +import type { createArrayOfUpdatesType, ArrayOfStringAnyTuple, StringAnyTuple } from "../types"; + export * from "./state_tools"; +export * from "./store_tools"; export * from "./poll"; + export const DAY = 24 * 60 * 60 * 1000; export function cleanupWorker(worker: Worker | undefined) { @@ -72,9 +76,7 @@ export const isMatch = ( }; -export type StringAnyTuple = [string, any] -export type ArrayOfStringAnyTuple = Array -export type createArrayOfUpdatesType = (oldRecord: Record, newRecord: Record) => ArrayOfStringAnyTuple + // compare records two entries deep and return an array of tuples export const createArrayOfUpdates:createArrayOfUpdatesType = (oldRecord, newRecord) => { let changeRegister: ArrayOfStringAnyTuple = Object.entries(oldRecord) @@ -94,5 +96,5 @@ export const createArrayOfUpdates:createArrayOfUpdatesType = (oldRecord, newReco return changeRegister; } -export const serializeFunction = (f: Function) => encodeURI(f.toString()); +export const serializeFunction = (f?: Function) => f ? encodeURI(f.toString()) : undefined; export const deserializeFunction = (s: string) => new Function(`return ${decodeURI(s)}`)(); \ No newline at end of file diff --git a/src/lib/utils/store_tools.ts b/src/lib/utils/store_tools.ts new file mode 100644 index 0000000..8c56994 --- /dev/null +++ b/src/lib/utils/store_tools.ts @@ -0,0 +1,20 @@ +import { del, get, set, update, createStore } from "idb-keyval"; + +import type { UseStore } from "idb-keyval"; + + +export function store () { + const DB_NAME = "usestore-db"; + const DB_STORE = "usestore-db"; + const store: UseStore = createStore(DB_NAME, DB_STORE); + const remove = (key: IDBValidKey) => del(key, store); + const getData = (key: IDBValidKey) => get(key, store); + const setData = (key: IDBValidKey, value: unknown) => set(key, value, store); + const updateData = (key: IDBValidKey, updater: (oldValue: any) => any) => update(key, updater, store); + return { + remove, + getData, + setData, + updateData, + }; +} \ No newline at end of file diff --git a/src/lib/workers/fetch_worker.ts b/src/lib/workers/fetch_worker.ts index 9b17bd6..d110c13 100644 --- a/src/lib/workers/fetch_worker.ts +++ b/src/lib/workers/fetch_worker.ts @@ -1,32 +1,18 @@ -import { del, get, set, update, createStore } from "idb-keyval"; import { deserializeFunction, methodType, isMatch, dataExpired, isObject, - type UnknownDataResponseType, + store, } from "../utils"; -import type { UseStore } from "idb-keyval"; import PollWorker from "./polling_worker.js?worker&inline"; -type ValueType = { timestamp: number; maxAge: number; data: any }; -type WorkerResponseType = MessageEvent< - { - type: string; - data?: UnknownDataResponseType; - } ->; +import type { WorkerResponseType, ValueType, FetchWorkerBaseRequestType } from "../types"; + +const { remove, getData, setData, updateData } = store(); -const DB_NAME = "usestore-db"; -const DB_STORE = "usestore-db"; -const store: UseStore = createStore(DB_NAME, DB_STORE); -const remove = (key: IDBValidKey) => del(key, store); -const getData = (key: IDBValidKey) => get(key, store); -const setData = (key: IDBValidKey, value: unknown) => set(key, value, store); -const updateData = (key: IDBValidKey, updater: (oldValue: any) => any) => - update(key, updater, store); const handleResponse = (response: Response) => { if (!response.ok || response.status === 404) { throw new Error(`HTTP error! Status: ${response.status}`); @@ -94,6 +80,32 @@ self.addEventListener( ); } + if (type === "pre-fetch") { + let { prefetch } = event.data; + prefetch.forEach((d: FetchWorkerBaseRequestType) => { + getData(d.url.toString()) + .then( + (value: ValueType) => { + if (!value) { + throw new Error("no value found in db"); + } + if (dataExpired(value?.maxAge, value?.timestamp)) { + remove(d.url.toString()); + throw new Error("data expired"); + } + }, + ) + .catch(() => { + fetch(d.url.toString(), { signal, ...d.options! }).then( + handleResponse, + ).then(data => { + let x = d.middleware ? d.middleware(data) : data; + setData(d.url.toString(), { timestamp: Date.now(), data: x, maxAge: d.maxAge! }); + }).catch(() => { console.info("no data found") }); + }); + }) + } + if (type === "fetch") { let { existingData, diff --git a/src/lib/workers/store_worker.ts b/src/lib/workers/store_worker.ts new file mode 100644 index 0000000..9f4e1ed --- /dev/null +++ b/src/lib/workers/store_worker.ts @@ -0,0 +1,79 @@ +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, + }); + }) + } + }, +); From 6eb505b191fa3513e45eb99ea48708ab34873011 Mon Sep 17 00:00:00 2001 From: Rod Lewis Date: Mon, 27 Jun 2022 20:51:28 +0800 Subject: [PATCH 4/5] fix preFetch --- dist/lib/types.d.ts | 3 ++ dist/lib/utils/index.d.ts | 2 +- dist/queryPlus.es.js | 71 +++++++++++++++++---------------- dist/queryPlus.umd.js | 2 +- src/lib/hooks/usePoll.tsx | 21 +++++----- src/lib/hooks/usePreFetch.tsx | 2 +- src/lib/types.d.ts | 3 ++ src/lib/utils/index.ts | 2 +- src/lib/workers/fetch_worker.ts | 38 ++++++------------ 9 files changed, 71 insertions(+), 73 deletions(-) diff --git a/dist/lib/types.d.ts b/dist/lib/types.d.ts index f87e456..57fb1a9 100644 --- a/dist/lib/types.d.ts +++ b/dist/lib/types.d.ts @@ -12,6 +12,9 @@ export interface FetchWorkerBaseRequestType { middleware?: (data: UnknownDataResponseType) => UnknownDataResponseType url: RequestInfo | URL } +export interface FetchWorkerRequestType extends FetchWorkerBaseRequestType { + middleware?: string +} export interface FetchWorkerProps extends FetchWorkerBaseRequestType { /* diff --git a/dist/lib/utils/index.d.ts b/dist/lib/utils/index.d.ts index e8d32f0..90b50c4 100644 --- a/dist/lib/utils/index.d.ts +++ b/dist/lib/utils/index.d.ts @@ -12,4 +12,4 @@ export declare const methodType: (options: RequestInit | undefined) => string; export declare const isMatch: (a: unknown, b: unknown, compareKeys?: string[] | undefined) => boolean; export declare const createArrayOfUpdates: createArrayOfUpdatesType; export declare const serializeFunction: (f?: Function | undefined) => string | undefined; -export declare const deserializeFunction: (s: string) => any; +export declare const deserializeFunction: (s?: string | undefined) => any; diff --git a/dist/queryPlus.es.js b/dist/queryPlus.es.js index 205ba7c..772e9f0 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 = "dmFyIGs9T2JqZWN0LmRlZmluZVByb3BlcnR5LEE9T2JqZWN0LmRlZmluZVByb3BlcnRpZXM7dmFyIGo9T2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcn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RhbXA6SyxtYXhBZ2U6ZixkYXRhOkh9fSkuY2F0Y2goKCk9Pntjb25zb2xlLmluZm8oInVwZGF0ZSBzdG9yZSBmYWlsZWQiKX0pLmZpbmFsbHkoKCk9PntzZWxmLnBvc3RNZXNzYWdlKHt0eXBlOiJDT01QTEVURSJ9KX0pfSkuY2F0Y2goUil9fSl9KSgpOwo="; 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); @@ -125,42 +125,44 @@ function useFetch() { }, state); } function usePoll(props) { - var _a, _b; const [state, dispatch] = useReducer(reducer, initialState); const worker = useRef(new WorkerWrapper()); - 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", + 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 - }); - else - dispatch({ - type: "error", - error: new Error(type) - }); - }); - (_b = worker.current) == null ? void 0 : _b.postMessage(__spreadProps(__spreadValues({ - type: "poll" - }, props), { - existingData: state.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); @@ -182,6 +184,7 @@ function usePreFetch(prefetch) { } }, [prefetch, worker.current]); useEffect(() => { + worker.current = new WorkerWrapper(); return () => { cleanupWorker(worker.current); }; diff --git a/dist/queryPlus.umd.js b/dist/queryPlus.umd.js index 679c803..8c75df8 100644 --- a/dist/queryPlus.umd.js +++ b/dist/queryPlus.umd.js @@ -1 +1 @@ -(function(Z,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):(Z=typeof globalThis!="undefined"?globalThis:Z||self,d(Z.queryPlus={},Z.React))})(this,function(Z,d){"use strict";var F=Object.defineProperty,y=Object.defineProperties;var J=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var x=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var X=(Z,d,W)=>d in Z?F(Z,d,{enumerable:!0,configurable:!0,writable:!0,value:W}):Z[d]=W,G=(Z,d)=>{for(var W in d||(d={}))x.call(d,W)&&X(Z,W,d[W]);if(S)for(var W of S(d))I.call(d,W)&&X(Z,W,d[W]);return Z},c=(Z,d)=>y(Z,J(d));const W="dmFyIGs9T2JqZWN0LmRlZmluZVByb3BlcnR5LEE9T2JqZWN0LmRlZmluZVByb3BlcnRpZXM7dmFyIGo9T2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcnM7dmFyIEI9T2JqZWN0LmdldE93blByb3BlcnR5U3ltYm9sczt2YXIgUT1PYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LHY9T2JqZWN0LnByb3RvdHlwZS5wcm9wZXJ0eUlzRW51bWVyYWJsZTt2YXIgRD0oaCxkLGwpPT5kIGluIGg/ayhoLGQse2VudW1lcmFibGU6ITAsY29uZmlndXJhYmxlOiEwLHdyaXRhYmxlOiEwLHZhbHVlOmx9KTpoW2RdPWwseT0oaCxkKT0+e2Zvcih2YXIgbCBpbiBkfHwoZD17fSkpUS5jYWxsKGQsbCkmJkQoaCxsLGRbbF0pO2lmKEIpZm9yKHZhciBsIG9mIEIoZCkpdi5jYWxsKGQsbCkmJkQoaCxsLGRbbF0pO3JldHVybiBofSxUPShoLGQpPT5BKGgsaihkKS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KSx7dGltZXN0YW1wOkgsbWF4QWdlOnAsZGF0YTpXfX0pLmNhdGNoKCgpPT57Y29uc29sZS5pbmZvKCJ1cGRhdGUgc3RvcmUgZmFpbGVkIil9KS5maW5hbGx5KCgpPT57c2VsZi5wb3N0TWVzc2FnZSh7dHlwZToiQ09NUExFVEUifSl9KX0pLmNhdGNoKFkpfX0pfSkoKTsK",h=typeof window!="undefined"&&window.Blob&&new Blob([atob(W)],{type:"text/javascript;charset=utf-8"});function a(){const l=h&&(window.URL||window.webkitURL).createObjectURL(h);try{return l?new Worker(l,{}):new Worker("data:application/javascript;base64,"+W,{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 t(l,b){switch(b.type){case"pre-load":return c(G({},l),{data:b.data,loading:!1,preload:!0,error:void 0});case"data":return c(G({},l),{data:b.data,loading:!1,preload:!1,error:void 0});case"error":return c(G({},l),{error:b.error,loading:!1,preload:!1});case"loading":return c(G({},l),{loading:b.loading});default:return l}}const k=24*60*60*1e3;function i(l){l==null||l.postMessage({type:"cancel"}),l==null||l.terminate(),l=void 0}const u=l=>l?encodeURI(l.toString()):void 0;function N(){const[l,b]=d.useReducer(t,T),p=d.useRef(),e=async({url:n,options:Y,maxAge:m=k,middleware:R})=>{let V=p.current;b({type:"loading",loading:!0}),V==null||V.addEventListener("message",({data:{type:o,data:U}})=>{switch(o){case"CACHED":case"COMPLETE":b({type:"loading",loading:!1});break;case"DATA":b({type:"data",data:U});break;case"PRE_LOAD":b({type:"pre-load",data:U});break;default:b({type:"error",error:new Error(o)});break}}),V==null||V.postMessage({type:"fetch",url:n,options:Y,existingData:l.data,middleware:u(R),maxAge:m})};return d.useEffect(()=>(p.current=new a,()=>{i(p.current)}),[]),G({fetchWorker:e},l)}function s(l){var n,Y;const[b,p]=d.useReducer(t,T),e=d.useRef(new a);return l&&e.current&&(p({type:"loading",loading:!0}),(n=e.current)==null||n.addEventListener("message",({data:{type:m,data:R}})=>{p(m==="COMPLETE"?{type:"loading",loading:!1}:m==="DATA"?{type:"data",data:R}:{type:"error",error:new Error(m)})}),(Y=e.current)==null||Y.postMessage(c(G({type:"poll"},l),{existingData:b.data}))),d.useEffect(()=>()=>{i(e.current)},[]),G({},b)}function K(l){const b=d.useRef(new a);d.useEffect(()=>{var p;l&&b.current&&((p=b.current)==null||p.postMessage({type:"pre-fetch",prefetch:l.map(e=>c(G({},e),{middleware:u(e.middleware)}))}))},[l,b.current]),d.useEffect(()=>()=>{i(b.current)},[])}Z.useFetch=N,Z.usePoll=s,Z.usePreFetch=K,Object.defineProperties(Z,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); +(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="dmFyIGs9T2JqZWN0LmRlZmluZVByb3BlcnR5LGo9T2JqZWN0LmRlZmluZVByb3BlcnRpZXM7dmFyIEE9T2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcnM7dmFyIFc9T2JqZWN0LmdldE93blByb3BlcnR5U3ltYm9sczt2YXIgUT1PYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LHY9T2JqZWN0LnByb3RvdHlwZS5wcm9wZXJ0eUlzRW51bWVyYWJsZTt2YXIgQj0oaC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ksSD1nKHMpJiZnKHk9PW51bGw/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"}})}); diff --git a/src/lib/hooks/usePoll.tsx b/src/lib/hooks/usePoll.tsx index 7e44f2f..dce4f8e 100644 --- a/src/lib/hooks/usePoll.tsx +++ b/src/lib/hooks/usePoll.tsx @@ -8,15 +8,18 @@ import type { WorkerResponseType, PollWorkerProps } from "../types"; export function usePoll(props: PollWorkerProps) { const [state, dispatch] = useReducer(reducer, initialState); const worker = useRef(new FetchWorker()); - 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 }); - } + + 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); diff --git a/src/lib/hooks/usePreFetch.tsx b/src/lib/hooks/usePreFetch.tsx index 223a720..e34b3d9 100644 --- a/src/lib/hooks/usePreFetch.tsx +++ b/src/lib/hooks/usePreFetch.tsx @@ -15,7 +15,7 @@ export function usePreFetch(prefetch?: Array) { }, [prefetch, worker.current]); useEffect(() => { - // worker.current = new FetchWorker() + worker.current = new FetchWorker() return () => { cleanupWorker(worker.current); } diff --git a/src/lib/types.d.ts b/src/lib/types.d.ts index f87e456..57fb1a9 100644 --- a/src/lib/types.d.ts +++ b/src/lib/types.d.ts @@ -12,6 +12,9 @@ export interface FetchWorkerBaseRequestType { middleware?: (data: UnknownDataResponseType) => UnknownDataResponseType url: RequestInfo | URL } +export interface FetchWorkerRequestType extends FetchWorkerBaseRequestType { + middleware?: string +} export interface FetchWorkerProps extends FetchWorkerBaseRequestType { /* diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 1937155..0ac111b 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -97,4 +97,4 @@ export const createArrayOfUpdates:createArrayOfUpdatesType = (oldRecord, newReco } export const serializeFunction = (f?: Function) => f ? encodeURI(f.toString()) : undefined; -export const deserializeFunction = (s: string) => new Function(`return ${decodeURI(s)}`)(); \ No newline at end of file +export const deserializeFunction = (s?: string) => s ? new Function(`return ${decodeURI(s)}`)() : (d:unknown) => d; \ No newline at end of file diff --git a/src/lib/workers/fetch_worker.ts b/src/lib/workers/fetch_worker.ts index d110c13..7ded2fe 100644 --- a/src/lib/workers/fetch_worker.ts +++ b/src/lib/workers/fetch_worker.ts @@ -9,7 +9,7 @@ import { import PollWorker from "./polling_worker.js?worker&inline"; -import type { WorkerResponseType, ValueType, FetchWorkerBaseRequestType } from "../types"; +import type { WorkerResponseType, ValueType, FetchWorkerRequestType } from "../types"; const { remove, getData, setData, updateData } = store(); @@ -82,27 +82,15 @@ self.addEventListener( if (type === "pre-fetch") { let { prefetch } = event.data; - prefetch.forEach((d: FetchWorkerBaseRequestType) => { - getData(d.url.toString()) - .then( - (value: ValueType) => { - if (!value) { - throw new Error("no value found in db"); - } - if (dataExpired(value?.maxAge, value?.timestamp)) { - remove(d.url.toString()); - throw new Error("data expired"); - } - }, - ) - .catch(() => { - fetch(d.url.toString(), { signal, ...d.options! }).then( - handleResponse, - ).then(data => { - let x = d.middleware ? d.middleware(data) : data; - setData(d.url.toString(), { timestamp: Date.now(), data: x, maxAge: d.maxAge! }); - }).catch(() => { console.info("no data found") }); - }); + prefetch.forEach(({middleware, url, options, maxAge}:FetchWorkerRequestType) => { + let fn = deserializeFunction(middleware); + fetch(url.toString(), { signal, ...options! }).then( + handleResponse, + ).then(data => { + setData(url.toString(), { timestamp: Date.now(), data: fn(data), maxAge: maxAge }) + .then(() => {console.log(`saved prefetch ${url}`)}) + .catch(err => {console.log(`error saving prefetch ${url}`, err)}); + }).catch(() => { console.info("no data found") }); }) } @@ -116,10 +104,8 @@ self.addEventListener( update, } = event.data; const handleData = (data: unknown) => { - if (middleware) { - let fn = deserializeFunction(middleware); - data = fn(data); - } + let fn = deserializeFunction(middleware); + data = fn(data); let hasChanged = !existingData || !isMatch(existingData, data); if (hasChanged) { self.postMessage({ type: "DATA", data }); From fce4fbab7bffd6c3c2ae8e177b5873b746f8463a Mon Sep 17 00:00:00 2001 From: Rod Lewis Date: Mon, 27 Jun 2022 20:56:58 +0800 Subject: [PATCH 5/5] usePreFetch hook --- dist/lib/hooks/usePoll.d.ts | 20 -------- dist/lib/index.d.ts | 1 - dist/lib/utils/index.d.ts | 1 - dist/lib/utils/poll.d.ts | 8 ---- dist/queryPlus.es.js | 50 +------------------ dist/queryPlus.umd.js | 2 +- src/lib/hooks/usePoll.tsx | 29 ------------ src/lib/hooks/useStore.tsx | 19 -------- src/lib/index.ts | 1 - src/lib/utils/index.ts | 1 - src/lib/utils/poll.ts | 35 -------------- src/lib/workers/fetch_worker.ts | 49 +------------------ src/lib/workers/polling_worker.ts | 35 -------------- src/lib/workers/store_worker.ts | 79 ------------------------------- 14 files changed, 5 insertions(+), 325 deletions(-) delete mode 100644 dist/lib/hooks/usePoll.d.ts delete mode 100644 dist/lib/utils/poll.d.ts delete mode 100644 src/lib/hooks/usePoll.tsx delete mode 100644 src/lib/hooks/useStore.tsx delete mode 100644 src/lib/utils/poll.ts delete mode 100644 src/lib/workers/polling_worker.ts delete mode 100644 src/lib/workers/store_worker.ts 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+e2Zvcih2YXIgbCBpbiBkfHwoZD17fSkpUS5jYWxsKGQsbCkmJkIoaCxsLGRbbF0pO2lmKFcpZm9yKHZhciBsIG9mIFcoZCkpdi5jYWxsKGQsbCkmJkIoaCxsLGRbbF0pO3JldHVybiBofSxUPShoLGQpPT5qKGgsQShkKSk7KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2Z1bmN0aW9uIGgodCl7cmV0dXJuIG5ldyBQcm9taXNlKChlLG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5jYXRjaCgoKT0+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="dmFyIGs9T2JqZWN0LmRlZmluZVByb3BlcnR5LGo9T2JqZWN0LmRlZmluZVByb3BlcnRpZXM7dmFyIEE9T2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcnM7dmFyIFc9T2JqZWN0LmdldE93blByb3BlcnR5U3ltYm9sczt2YXIgUT1PYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LHY9T2JqZWN0LnByb3RvdHlwZS5wcm9wZXJ0eUlzRW51bWVyYWJsZTt2YXIgQj0oaCxkLGwpPT5kIGluIGg/ayhoLGQse2VudW1lcmFibGU6ITAsY29uZmlndXJhYmxlOiEwLHdyaXRhYmxlOiEwLHZhbHVlOmx9KTpoW2RdPWwsWj0oaCxkKT0+e2Zvcih2YXIgbCBpbiBkfHwoZD17fSkpUS5jYWxsKGQsbCkmJkIoaCxsLGRbbF0pO2lmKFcpZm9yKHZhciBsIG9mIFcoZCkpdi5jYWxsKGQsbCkmJkIoaCxsLGRbbF0pO3JldHVybiBofSxUPShoLGQpPT5qKGgsQShkKSk7KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2Z1bmN0aW9uIGgodCl7cmV0dXJuIG5ldyBQcm9taXNlKChlLG4pPT57dC5vbmNvbXBsZXRlPXQub25zdWNjZXNzPSgpPT5lKHQucmVzdWx0KSx0Lm9uYWJvcnQ9dC5vbmVycm9yPSgpPT5uKHQuZXJyb3IpfSl9ZnVuY3Rpb24gZCh0LGUpe2NvbnN0IG49aW5kZXhlZERC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XRhIGV4cGlyZWQiKTtzZWxmLnBvc3RNZXNzYWdlKEcocixzPT1udWxsP3ZvaWQgMDpzLmRhdGEpP3t0eXBlOiJDQUNIRUQifTp7dHlwZToiUFJFX0xPQUQiLGRhdGE6cz09bnVsbD92b2lkIDA6cy5kYXRhfSl9KS5jYXRjaChzPT57Y29uc29sZS5pbmZvKHM9PW51bGw/dm9pZCAwOnMubWVzc2FnZSl9KSxmZXRjaChpLG8/VChaKHt9LG8pLHtzaWduYWw6Y30pOntzaWduYWw6Y30pLnRoZW4oUykudGhlbihwKS5jYXRjaChSKSksKGI9PT0iUFVUInx8Yj09PSJQT1NUIikmJmZldGNoKGksbz9UKFooe30sbykse3NpZ25hbDpjfSk6e3NpZ25hbDpjfSkudGhlbihTKS50aGVuKHM9PnttP2ZldGNoKG0udXJsLG0ub3B0aW9ucykudGhlbihTKS50aGVuKHApLmNhdGNoKHk9Pnt0aHJvdyB5fSk6VihpLnRvU3RyaW5nKCkseT0+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||(d={}))r.call(d,b)&&s(l,b,d[b]);if(Y)for(var b of Y(d))C.call(d,b)&&s(l,b,d[b]);return l},n=(l,d)=>V(l,N(d));const b="dmFyIGI9T2JqZWN0LmRlZmluZVByb3BlcnR5LEk9T2JqZWN0LmRlZmluZVByb3BlcnRpZXM7dmFyIFE9T2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcnM7dmFyIFI9T2JqZWN0LmdldE93blByb3BlcnR5U3ltYm9sczt2YXIgVz1PYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LFg9T2JqZWN0LnByb3RvdHlwZS5wcm9wZXJ0eUlzRW51bWVyYWJsZTt2YXIgVT0oaSxmLGgpPT5mIGluIGk/YihpLGYse2VudW1lcmFibGU6ITAsY29uZmlndXJhYmxlOiEwLHdyaXRhYmxlOiEwLHZhbHVlOmh9KTppW2ZdPWgsbD0oaSxmKT0+e2Zvcih2YXIgaCBpbiBmfHwoZj17fSkpVy5jYWxsKGYsaCkmJlUoaSxoLGZbaF0pO2lmKFIpZm9yKHZhciBoIG9mIFIoZikpWC5jYWxsKGYsaCkmJlUoaSxoLGZbaF0pO3JldHVybiBpfSxUPShpLGYpPT5JKGksUShmKSk7KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2Z1bmN0aW9uIGkodCl7cmV0dXJ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NpZ25hbDpyfSk6e3NpZ25hbDpyfSkudGhlbihEKS50aGVuKEUpLmNhdGNoKFMpKSwodT09PSJQVVQifHx1PT09IlBPU1QiKSYmZmV0Y2gocyxjP1QobCh7fSxjKSx7c2lnbmFsOnJ9KTp7c2lnbmFsOnJ9KS50aGVuKEQpLnRoZW4obz0+e3A/ZmV0Y2gocC51cmwscC5vcHRpb25zKS50aGVuKEQpLnRoZW4oRSkuY2F0Y2goeT0+e3Rocm93IHl9KTpOKHMudG9TdHJpbmcoKSx5PT57bGV0IHg9RGF0ZS5ub3coKSxMPUEobykmJkEoeT09bnVsbD92b2lkIDA6eS5kYXRhKT9sKGwoe30seS5kYXRhKSxvKTpvO3JldHVybiBzZWxmLnBvc3RNZXNzYWdlKHt0eXBlOnUsZGF0YTpMfSkse3RpbWVzdGFtcDp4LG1heEFnZTpkLGRhdGE6TH19KS5jYXRjaCgoKT0+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, - }); - }) - } - }, -);