Skip to content

Commit 2fa0d2f

Browse files
authored
Merge pull request #18 from StudentOfJS/coords
replace FetchWithIntent component with useIntent hook
2 parents 4fedcc2 + 291cbf3 commit 2fa0d2f

File tree

14 files changed

+190
-173
lines changed

14 files changed

+190
-173
lines changed

README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,31 @@ usePrefetch to pre fetch data and save it for faster retrival later.
6767

6868

6969

70-
## FetchWithIntent
70+
## useIntent
7171

72-
This is a React component used for prefetching data based on a user's percieved intent.
72+
This is a React hook used for prefetching data based on a user's percieved intent.
7373

7474
### example
7575

76-
<FetchWithIntent timeToExcecute={1000} prefetch={[{ url: 'https://swapi.dev/api/people/3/' }]}>
77-
<div className="App">
76+
function App() {
77+
const ref = useRef<HTMLDivElement>(null)
78+
useIntent<HTMLDivElement>({prefetch:[{ url: 'https://swapi.dev/api/people/3/' }],targetRef: ref, expandTarget: 100, timeToExcecute: 2000 })
79+
return (
80+
<div ref={ref}>
81+
<div className="App">
7882
<Droid />
83+
</div>
7984
</div>
80-
</FetchWithIntent>
85+
86+
)
87+
}
88+
8189
### props
8290

83-
- timeToExecute - optional time in ms required for the user to have their mouse cursor in the boundaries of the component before prefetch is initiated. Defaults to 1000.
84-
- required array of fetch objects. See usePreFetch above.
91+
- expandTarget - optional number, increase the target boundary beyond your element.
92+
- timeToExecute - optional time in ms required for the user to have their mouse cursor in the boundaries of the target area before prefetch is initiated. Defaults to 1000.
93+
- prefetch - required array of fetch objects. See usePreFetch above.
94+
- targetRef - the refference of the element you wish to use as the target.
8595

8696

8797

@@ -129,9 +139,4 @@ Data fetching, data processing and data storage tasks run in a web worker. This
129139

130140

131141

132-
133-
134-
135-
136-
137-
Thanks to [Jake Archibald](https://github.com/jakearchibald) for creating [idb-keyval](https://github.com/jakearchibald/idb). Enabling us to easily access indexedDB with a really nice promise based api.
142+
Thanks to [Jake Archibald](https://github.com/jakearchibald) for creating [idb-keyval](https://github.com/jakearchibald/idb). Enabling us to easily access indexedDB with a really nice promise based api.

dist/lib/components/FetchWithIntent.d.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

dist/lib/hooks/useEventListener.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface UseEventListenerOptions {
2+
eventName: string;
3+
handler: (event: any) => void;
4+
options?: Record<string, any>;
5+
}
6+
declare const useEventListener: ({ eventName, handler, options }: UseEventListenerOptions) => ((() => void) | undefined)[];
7+
export default useEventListener;

dist/lib/hooks/useIntent.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { FetchWorkerBaseRequestType } from "../types";
2+
interface UseIntentOptions<T> {
3+
expandTarget?: number;
4+
targetRef: React.RefObject<T>;
5+
prefetch: Array<FetchWorkerBaseRequestType>;
6+
timeToExcecute?: number;
7+
}
8+
export declare function useIntent<T extends HTMLElement>({ expandTarget, targetRef, prefetch, timeToExcecute }: UseIntentOptions<T>): void;
9+
export {};

dist/lib/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export { useFetch } from './hooks/useFetch';
22
export { usePreFetch } from './hooks/usePreFetch';
3-
export { FetchWithIntent } from './components/FetchWithIntent';
3+
export { useIntent } from './hooks/useIntent';

dist/queryPlus.es.js

Lines changed: 69 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import require$$0, { useReducer, useRef, useEffect, useState } from "react";
1+
import { useReducer, useRef, useEffect, useState } from "react";
22
import "idb-keyval";
33
const encodedJs = "KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2Z1bmN0aW9uIHAodCl7cmV0dXJuIG5ldyBQcm9taXNlKChlLG4pPT57dC5vbmNvbXBsZXRlPXQub25zdWNjZXNzPSgpPT5lKHQucmVzdWx0KSx0Lm9uYWJvcnQ9dC5vbmVycm9yPSgpPT5uKHQu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ldGNoKG8saT97Li4uaSxzaWduYWw6cn06e3NpZ25hbDpyfSkudGhlbihnKS50aGVuKHUpLmNhdGNoKG0pKSksKGw9PT0iUFVUInx8bD09PSJQT1NUIikmJihzZWxmLnBvc3RNZXNzYWdlKHt0eXBlOiJMT0FESU5HIn0pLGZldGNoKG8saT97Li4uaSxzaWduYWw6cn06e3NpZ25hbDpyfSkudGhlbihnKS50aGVuKHM9PntkP2ZldGNoKGQudXJsLGQub3B0aW9ucykudGhlbihnKS50aGVuKHUpLmNhdGNoKGY9Pnt0aHJvdyBmfSk6RihvLnRvU3RyaW5nKCksZj0+e2xldCBFPURhdGUubm93KCksQj1EKHMpJiZEKGY9PW51bGw/dm9pZCAwOmYuZGF0YSk/ey4uLmYuZGF0YSwuLi5zfTpzO3JldHVybiBzZWxmLnBvc3RNZXNzYWdlKHt0eXBlOmwsZGF0YTpCfSkse3RpbWVzdGFtcDpFLG1heEFnZTpoLGRhdGE6Qn19KS5jYXRjaCgoKT0+e2NvbnNvbGUuaW5mbygidXBkYXRlIHN0b3JlIGZhaWxlZCIpfSkuZmluYWxseSgoKT0+e3NlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6IkNPTVBMRVRFIn0pfSl9KS5jYXRjaChtKSl9fSl9KSgpOwo=";
44
const blob = typeof window !== "undefined" && window.Blob && new Blob([atob(encodedJs)], { type: "text/javascript;charset=utf-8" });
@@ -37,149 +37,110 @@ function cleanupWorker(worker) {
3737
worker == null ? void 0 : worker.terminate();
3838
worker = void 0;
3939
}
40-
const serializeFunction = (f2) => f2 ? encodeURI(f2.toString()) : void 0;
40+
const serializeFunction = (f) => f ? encodeURI(f.toString()) : void 0;
4141
function useFetch() {
4242
const [state, dispatch] = useReducer(reducer, initialState);
4343
const workerRef = useRef();
44-
const fetchWorker = async ({
45-
url,
46-
options,
47-
maxAge = DAY,
48-
preferUseCache,
49-
middleware
50-
}) => {
44+
const fetchWorker = async ({ url, options, maxAge = DAY, preferUseCache, middleware }) => {
5145
let worker = workerRef.current;
52-
worker == null ? void 0 : worker.addEventListener("message", ({
53-
data: {
54-
type,
55-
data
56-
}
57-
}) => {
46+
worker == null ? void 0 : worker.addEventListener("message", ({ data: { type, data } }) => {
5847
switch (type) {
5948
case "LOADING":
60-
dispatch({
61-
type: "loading",
62-
loading: true
63-
});
49+
dispatch({ type: "loading", loading: true });
6450
break;
6551
case "CACHED":
6652
case "COMPLETE":
67-
dispatch({
68-
type: "loading",
69-
loading: false
70-
});
53+
dispatch({ type: "loading", loading: false });
7154
break;
7255
case "DATA":
73-
dispatch({
74-
type: "data",
75-
data
76-
});
56+
dispatch({ type: "data", data });
7757
break;
7858
case "PRE_LOAD":
79-
dispatch({
80-
type: "pre-load",
81-
data
82-
});
59+
dispatch({ type: "pre-load", data });
8360
break;
8461
default:
85-
dispatch({
86-
type: "error",
87-
error: new Error(type)
88-
});
62+
dispatch({ type: "error", error: new Error(type) });
8963
break;
9064
}
9165
});
92-
worker == null ? void 0 : worker.postMessage({
93-
type: "fetch",
94-
url,
95-
options,
96-
existingData: state.data,
97-
middleware: serializeFunction(middleware),
98-
maxAge,
99-
preferUseCache
100-
});
66+
worker == null ? void 0 : worker.postMessage({ type: "fetch", url, options, existingData: state.data, middleware: serializeFunction(middleware), maxAge, preferUseCache });
10167
};
10268
useEffect(() => {
10369
workerRef.current = new WorkerWrapper();
10470
return () => {
10571
cleanupWorker(workerRef.current);
10672
};
10773
}, []);
108-
return {
109-
fetchWorker,
110-
...state
111-
};
74+
return { fetchWorker, ...state };
11275
}
11376
function usePreFetch(prefetch) {
11477
const worker = useRef(new WorkerWrapper());
11578
useEffect(() => {
11679
var _a;
11780
if (prefetch && worker.current) {
118-
(_a = worker.current) == null ? void 0 : _a.postMessage({
119-
type: "pre-fetch",
120-
prefetch: prefetch.map((p2) => ({
121-
...p2,
122-
middleware: serializeFunction(p2.middleware)
123-
}))
124-
});
81+
(_a = worker.current) == null ? void 0 : _a.postMessage({ type: "pre-fetch", prefetch: prefetch.map((p) => ({ ...p, middleware: serializeFunction(p.middleware) })) });
12582
}
12683
}, [prefetch, worker.current]);
12784
}
128-
var jsxRuntime = { exports: {} };
129-
var reactJsxRuntime_production_min = {};
130-
/**
131-
* @license React
132-
* react-jsx-runtime.production.min.js
133-
*
134-
* Copyright (c) Facebook, Inc. and its affiliates.
135-
*
136-
* This source code is licensed under the MIT license found in the
137-
* LICENSE file in the root directory of this source tree.
138-
*/
139-
var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: true, ref: true, __self: true, __source: true };
140-
function q(c, a, g) {
141-
var b, d = {}, e = null, h = null;
142-
g !== void 0 && (e = "" + g);
143-
a.key !== void 0 && (e = "" + a.key);
144-
a.ref !== void 0 && (h = a.ref);
145-
for (b in a)
146-
m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
147-
if (c && c.defaultProps)
148-
for (b in a = c.defaultProps, a)
149-
d[b] === void 0 && (d[b] = a[b]);
150-
return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
151-
}
152-
reactJsxRuntime_production_min.Fragment = l;
153-
reactJsxRuntime_production_min.jsx = q;
154-
reactJsxRuntime_production_min.jsxs = q;
155-
{
156-
jsxRuntime.exports = reactJsxRuntime_production_min;
157-
}
158-
const jsx = jsxRuntime.exports.jsx;
159-
const FetchWithIntent = ({
160-
children,
161-
prefetch,
162-
timeToExcecute = 1e3
85+
const useEventListener = ({
86+
eventName,
87+
handler,
88+
options = {}
16389
}) => {
90+
const savedHandler = useRef();
91+
const removeHanlder = useRef();
92+
const { capture, passive, once } = options;
93+
const element = window.document.body;
94+
useEffect(() => {
95+
savedHandler.current = handler;
96+
}, [handler]);
97+
useEffect(() => {
98+
const isSupported = element && element.addEventListener;
99+
if (!isSupported) {
100+
return;
101+
}
102+
const eventListener = (event) => savedHandler.current && savedHandler.current(event);
103+
const opts = { capture, passive, once };
104+
element.addEventListener(eventName, eventListener, opts);
105+
const remove = () => element.removeEventListener(eventName, eventListener, opts);
106+
removeHanlder.current = remove;
107+
return remove;
108+
}, [eventName, element, capture, passive, once]);
109+
return [removeHanlder.current];
110+
};
111+
function useIntent({ expandTarget = 0, targetRef, prefetch, timeToExcecute = 1e3 }) {
164112
const [prefetchConfig, setprefetchConfig] = useState();
113+
const [once, setOnce] = useState(false);
165114
const timer = useRef();
166115
usePreFetch(prefetchConfig);
167-
const handleClearTimeout = () => {
168-
if (timer.current) {
169-
clearTimeout(timer.current);
170-
}
171-
};
172-
const handleMouseEnter = () => {
173-
handleClearTimeout();
174-
timer.current = setTimeout(() => {
175-
setprefetchConfig(prefetch);
176-
}, timeToExcecute);
177-
};
178-
useEffect(() => handleClearTimeout, []);
179-
return /* @__PURE__ */ jsx("div", {
180-
onMouseEnter: handleMouseEnter,
181-
onMouseLeave: handleClearTimeout,
182-
children
116+
const [remove] = useEventListener({
117+
eventName: "mousemove",
118+
handler: ({ clientX, clientY }) => {
119+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
120+
let left = ((_b = (_a = targetRef.current) == null ? void 0 : _a.offsetLeft) != null ? _b : 0) - expandTarget;
121+
let right = ((_d = (_c = targetRef.current) == null ? void 0 : _c.offsetLeft) != null ? _d : 0) + ((_f = (_e = targetRef.current) == null ? void 0 : _e.offsetWidth) != null ? _f : 0) + expandTarget;
122+
let top = ((_h = (_g = targetRef.current) == null ? void 0 : _g.offsetTop) != null ? _h : 0) - expandTarget;
123+
let bottom = ((_j = (_i = targetRef.current) == null ? void 0 : _i.offsetTop) != null ? _j : 0) + ((_l = (_k = targetRef.current) == null ? void 0 : _k.offsetHeight) != null ? _l : 0) + expandTarget;
124+
if (clientX > left && clientX < right && clientY > top && clientY < bottom) {
125+
console.info("in target area");
126+
if (!timer.current) {
127+
timer.current = setTimeout(() => {
128+
setprefetchConfig(prefetch);
129+
setOnce(true);
130+
remove && remove();
131+
}, timeToExcecute);
132+
}
133+
} else {
134+
if (timer.current) {
135+
clearTimeout(timer.current);
136+
timer.current = void 0;
137+
}
138+
}
139+
},
140+
options: { passive: true, once }
183141
});
184-
};
185-
export { FetchWithIntent, useFetch, usePreFetch };
142+
useEffect(() => () => {
143+
clearTimeout(timer.current);
144+
}, []);
145+
}
146+
export { useFetch, useIntent, usePreFetch };

0 commit comments

Comments
 (0)