🔧 Fixes to web workers

This commit is contained in:
2021-04-26 15:54:39 -07:00
parent 0701ef19f8
commit 15dcdcfe43
6 changed files with 39 additions and 22 deletions

View File

@@ -3,6 +3,7 @@ import _ from "lodash";
import { connect } from "react-redux";
import * as Comlink from "comlink";
import { wrap, proxy } from "comlink";
import { useWorker } from "react-hooks-worker";
interface IProps {
matches: unknown;
}
@@ -11,6 +12,16 @@ interface IState {
searchPaneIndex: number;
}
const createWorker = () =>
// new Worker("../workers/extractCovers.worker.js", {
// type: "module",
// });
new Worker(new URL("../workers/extractCovers.worker.js", import.meta.url));
const CalcFib = ({ count }) => {
const con = useWorker(createWorker, count);
console.log(con);
return <div>jagnya</div>
};
class Import extends React.Component<IProps, IState> {
constructor(props: IProps) {
super(props);
@@ -26,16 +37,7 @@ class Import extends React.Component<IProps, IState> {
});
}
public async startFolderWalk() {
const multiply = wrap(
new Worker(
"http://localhost:3000/src/client/workers/extractCovers.worker.js",
{ type: "module" },
),
);
const sutarfeni = await proxy(multiply);
console.log("foo", sutarfeni());
}
public async startFolderWalk() {}
public render() {
return (
<div>
@@ -81,7 +83,12 @@ class Import extends React.Component<IProps, IState> {
{/* Folder walk results */}
{!_.isUndefined(this.state.folderWalkResults) ? (
<>
<div>poopie</div>
<div>
poopie
<div>
<CalcFib count={5} />
</div>
</div>
</>
) : null}
</section>