🪛 Workers!
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
|
import * as Comlink from "comlink";
|
||||||
|
import ExpensiveProcessor from "worker-loader!../workers/extractCovers.worker";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
matches: unknown;
|
matches: unknown;
|
||||||
}
|
}
|
||||||
@@ -25,11 +28,8 @@ class Import extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async startFolderWalk() {
|
public async startFolderWalk() {
|
||||||
const worker = new Worker(
|
const worker = Comlink.proxy(new ExpensiveProcessor());
|
||||||
new URL("../workers/extractCovers.worker", import.meta.url),
|
console.log(new worker());
|
||||||
);
|
|
||||||
|
|
||||||
console.log(worker);
|
|
||||||
}
|
}
|
||||||
public render() {
|
public render() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
8
src/client/types/index.d.ts
vendored
8
src/client/types/index.d.ts
vendored
@@ -2,11 +2,17 @@ declare module "*.png" {
|
|||||||
const value: string;
|
const value: string;
|
||||||
export = value;
|
export = value;
|
||||||
}
|
}
|
||||||
|
// declare module "*.worker.ts" {
|
||||||
|
// class ImportComicBooksWorker extends Worker {
|
||||||
|
// constructor();
|
||||||
|
// }
|
||||||
|
// export default ImportComicBooksWorker;
|
||||||
|
// }
|
||||||
|
|
||||||
declare module "worker-loader!*" {
|
declare module "worker-loader!*" {
|
||||||
class WebpackWorker extends Worker {
|
class WebpackWorker extends Worker {
|
||||||
constructor();
|
constructor();
|
||||||
}
|
}
|
||||||
|
|
||||||
export default WebpackWorker;
|
export default WebpackWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
|
// const worker: DedicatedWorkerGlobalScope = self as any;
|
||||||
|
|
||||||
|
// worker.onmessage = ({ data }) => {
|
||||||
|
// if (data instanceof Array) {
|
||||||
|
// worker.postMessage(data.join(" ") + "!");
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
import { expose } from "comlink";
|
import { expose } from "comlink";
|
||||||
|
|
||||||
const foo = (value: string) => {
|
class ExpensiveProcessor {
|
||||||
return "rishi" + " " + value;
|
_foo: string;
|
||||||
};
|
/* ... async methods here ... */
|
||||||
|
constructor() {
|
||||||
|
this._foo = "rishi";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const bar = (value: number) => {
|
expose(ExpensiveProcessor, self);
|
||||||
return value + 10;
|
|
||||||
};
|
|
||||||
|
|
||||||
const exported = {
|
|
||||||
foo,
|
|
||||||
bar,
|
|
||||||
};
|
|
||||||
|
|
||||||
export type Worker = typeof exported;
|
|
||||||
expose(exported);
|
|
||||||
|
|||||||
@@ -5,9 +5,10 @@
|
|||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"target": "es2019",
|
"target": "es2019",
|
||||||
"jsx": "react",
|
"jsx": "react",
|
||||||
"module": "esnext",
|
"module": "commonjs",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"outDir": "./dist/",
|
"outDir": "./dist/",
|
||||||
|
"noImplicitAny": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"lib": [
|
"lib": [
|
||||||
"dom",
|
"dom",
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
// new CleanWebpackPlugin([outputDirectory]),
|
// new CleanWebpackPlugin([outputDirectory]),
|
||||||
new WorkerPlugin(),
|
// new WorkerPlugin(),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: "./public/index.html",
|
template: "./public/index.html",
|
||||||
favicon: "./public/favicon.ico",
|
favicon: "./public/favicon.ico",
|
||||||
|
|||||||
Reference in New Issue
Block a user