mirror of
https://github.com/filecoin-project/slate.git
synced 2024-08-17 17:50:50 +03:00
feat(web-workers):
- add useWorker to interact with web workers declaratively - update next to 11.1.2 to support web-workers - update next config to ignore eslint errors during build
This commit is contained in:
parent
24b09cf0ba
commit
2c601066a6
@ -424,3 +424,30 @@ export const useLockScroll = ({ lock = true } = {}) => {
|
||||
return () => (document.body.style.overflow = "visible");
|
||||
}, [lock]);
|
||||
};
|
||||
|
||||
export const useWorker = ({ onStart, onMessage, onError, path } = {}, dependencies = []) => {
|
||||
const workerRef = React.useRef();
|
||||
|
||||
const onStartRef = React.useRef();
|
||||
onStartRef.current = onStart;
|
||||
|
||||
const onMessageRef = React.useRef();
|
||||
onMessageRef.current = onMessage;
|
||||
|
||||
const onErrorRef = React.useRef();
|
||||
onErrorRef.current = onError;
|
||||
|
||||
React.useEffect(() => {
|
||||
const worker = new Worker(new URL(path, import.meta.url));
|
||||
if (!worker) return;
|
||||
|
||||
workerRef.current = worker;
|
||||
worker.onmessage = onMessageRef.current;
|
||||
worker.onerror = onErrorRef.current;
|
||||
|
||||
onStartRef.current(worker);
|
||||
return () => worker?.terminate();
|
||||
}, dependencies);
|
||||
|
||||
return workerRef.current;
|
||||
};
|
||||
|
@ -2,6 +2,11 @@ const withOffline = require("next-offline");
|
||||
|
||||
const nextConfig = {
|
||||
webpack5: true,
|
||||
eslint: {
|
||||
// Warning: This allows production builds to successfully complete even if
|
||||
// your project has ESLint errors.
|
||||
ignoreDuringBuilds: true,
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = withOffline(nextConfig);
|
||||
|
@ -65,7 +65,7 @@
|
||||
"moment": "^2.29.1",
|
||||
"morgan": "^1.10.0",
|
||||
"multihashing-async": "^2.1.2",
|
||||
"next": "^10.0.7",
|
||||
"next": "^11.1.2",
|
||||
"next-offline": "^5.0.5",
|
||||
"oauth": "^0.9.15",
|
||||
"pg": "^8.5.1",
|
||||
|
Loading…
Reference in New Issue
Block a user