dutyfree
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Duty Free 🛍️

Create web workers with callbacks


dependencies Status devDependencies Status License: MIT

The problem

Creating web worker files is difficult, when you are using build tools and frameworks. Making sure your web worker scripts end up in the right path after build is a hassle.

This solution ✨

Duty Free will allow you to create your web workers with just a callback; no extra files needed.

Features

  • No Dependencies - no dependencies
  • TypeScript - Everything is TypeScript based
  • Lint - Pre-configured ESlint with Airbnb config
  • Small - It almost doesn't exist

Limitations

This package is constrained by limitations of Web Workers, and Function.prototype.toString. Please be aware of the following, before using it:

  • Please note that you do have to pass in a function defined by a Function Declaration, not a Function Expression.

  • You cannot use imports in your callback. Scoping rules do not apply here. Visit here for more info.

  • If you use a module bundler like Webpack, ensure you are writing your callback is compatible with the target ES version (likely ES5), otherwise the bundler will modify the code, where it will not run in the isolation, while it needs to.

Installation

This module is distributed via npm which should be installed as one of your project's dependencies:

npm i --save dutyfree

Usage

  • Install dutyfree
  • Import createWorker from the package
  • Pass your callback to dutyfree.
  • Your instance is ready
import { createWorker } from "dutyfree";

function source() {
  onmessage = function (e) {
    postMessage(`Worker says ${e.data}`);
  };
}

const myWorker = createWorker(source);

myWorker.onmessage = function (e) {
  console.log("Received: " + e.data);
};

worker.postMessage("Dooti");

worker.terminate();

Contributing

This package is a beginner-friendly package. If you don't know where to start, visit Make a Pull Request to learn how to make pull requests.

Please visit Contributing for more info.

Code of Conduct

Please visit Code of Conduct.


License

MIT

Package Sidebar

Install

npm i dutyfree

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

8.75 kB

Total Files

17

Last publish

Collaborators

  • parsasi