1.2.11 • Published 3 years ago

rewrk v1.2.11

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Rewrk

Version Prerequisite License: MIT

Dead simple React web workers.

API

useWorker<T extends Record<string, unknown>>(dynamicImport: Promise<T>, options?: WorkerOptions): ProxiedWorkerMethods<T>

Creates a worker from a dynamic import and returns a proxy object that can be used to call the worker's exported functions.

Arguments

  • dynamicImport - A function that returns dynamic import of the worker module. The module must export at least one function. Non-function exports will be stripped away.
  • options? - Options to pass to the worker constructor. By default the type option is set to "module".

Returns

A proxy object that can be used to call the worker's exported functions. The proxy object will be available immidiately despite the dynamic import returning a Promise.

Usage

import { useWorker } from "rewrk";

const WorkerComponent = () => {
    const worker = useWorker(import("./worker"));

    return <button onClick={() => worker.doSomething()}>Do something</button>;
};

License

MIT © Juan de Urtubey

1.2.11

3 years ago

1.2.10

3 years ago

1.2.9

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.0

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.6

3 years ago