Skip to content

Commit

Permalink
feat: remove isoworker and localdeps feature
Browse files Browse the repository at this point in the history
feat: removed test and packages
  • Loading branch information
alewin committed Mar 21, 2021
1 parent 011d2a3 commit 9bd4ebc
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 12,716 deletions.
12,677 changes: 0 additions & 12,677 deletions package-lock.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
- Buble Sort ( complex calculation )
- External Scripts ( `removeDependencies` option example )
- Transferable ( `transferable` option example )
- LocalDeps ( `localDependencies` option example )
<!-- - LocalDeps ( `localDependencies` option example ) -->
3 changes: 1 addition & 2 deletions packages/useWorker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"background"
],
"dependencies": {
"dequal": "^1.0.0",
"isoworker": "^0.1.1"
"dequal": "^1.0.0"
}
}
12 changes: 4 additions & 8 deletions packages/useWorker/src/lib/createWorkerBlobUrl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import isoworker from 'isoworker'
import { TRANSFERABLE_TYPE } from 'src/useWorker'
// import isoworker from 'isoworker'
import { TRANSFERABLE_TYPE } from '../useWorker'
import jobRunner from './jobRunner'
import remoteDepsParser from './remoteDepsParser'

Expand All @@ -18,15 +18,11 @@ import remoteDepsParser from './remoteDepsParser'
* .catch(postMessage(['ERROR', error])"
*/
const createWorkerBlobUrl = (
fn: Function,
deps: string[],
transferable: TRANSFERABLE_TYPE,
localDeps: () => unknown[],
fn: Function, deps: string[], transferable: TRANSFERABLE_TYPE, /* localDeps: () => unknown[], */
) => {
const [context] = isoworker.createContext(localDeps)
// const [context] = isoworker.createContext(localDeps)
const blobCode = `
${remoteDepsParser(deps)};
${context}
onmessage=(${jobRunner})({
fn: (${fn}),
transferable: '${transferable}'
Expand Down
8 changes: 4 additions & 4 deletions packages/useWorker/src/useWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Options = {
remoteDependencies?: string[];
autoTerminate?: boolean;
transferable?: TRANSFERABLE_TYPE;
localDependencies?: () => unknown[];
// localDependencies?: () => unknown[];
}

const PROMISE_RESOLVE = 'resolve'
Expand All @@ -28,7 +28,7 @@ const DEFAULT_OPTIONS: Options = {
remoteDependencies: [],
autoTerminate: true,
transferable: TRANSFERABLE_TYPE.AUTO,
localDependencies: () => [],
// localDependencies: () => [],
}


Expand Down Expand Up @@ -80,10 +80,10 @@ export const useWorker = <T extends (...fnArgs: any[]) => any>(
remoteDependencies = DEFAULT_OPTIONS.remoteDependencies,
timeout = DEFAULT_OPTIONS.timeout,
transferable = DEFAULT_OPTIONS.transferable,
localDependencies = DEFAULT_OPTIONS.localDependencies,
// localDependencies = DEFAULT_OPTIONS.localDependencies,
} = options

const blobUrl = createWorkerBlobUrl(fn, remoteDependencies!, transferable!, localDependencies!)
const blobUrl = createWorkerBlobUrl(fn, remoteDependencies!, transferable! /*, localDependencies!*/)
const newWorker: Worker & { _url?: string } = new Worker(blobUrl)
newWorker._url = blobUrl

Expand Down
7 changes: 4 additions & 3 deletions packages/useWorker/test/localDeps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { renderHook } from "@testing-library/react-hooks";

const adder = (a, b) => a + b;

it("Return", async () => {
const sum = (a, b) => adder(a, b);
it("localDependencies", async () => {
/* const sum = (a, b) => adder(a, b);
const { result } = renderHook(() =>
useWorker(sum, { localDependencies: () => [adder] })
);
const [sumWorker] = result.current;
const res = await sumWorker(1, 2);
assert.equal(res, 3);
assert.equal(res, 3); */
assert.equal(1, 1);
});
14 changes: 0 additions & 14 deletions packages/useWorker/test/localDepsImport.test.js

This file was deleted.

4 changes: 3 additions & 1 deletion packages/website/docs/useworker.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ to view the values of `WORKER_STATUS` click here: [Status API](./workerstatus.md
| ------------------ | --------------- | --------- | ------------------------------------------------------------------------- |
| timeout | Number | undefined | The number of milliseconds before killing the worker |
| remoteDependencies | Array of String | [] | An array that contains the remote dependencies needed to run the worker |
| localDependencies | Function of Array of String | () => [] | A function that returns an array that contains the local dependencies needed to run the worker |
<!-- | localDependencies | Function of Array of String | () => [] | A function that returns an array that contains the local dependencies needed to run the worker | -->
| autoTerminate | Boolean | true | Kill the worker once it's done (success or error) |
| transferable | String | 'auto' | Enable [Transferable Objects](https://developer.mozilla.org/en-US/docs/Web/API/Transferable), to disable it set transferable: 'none' |

Expand All @@ -61,6 +61,7 @@ const [workerFn, {status: workerStatus, kill: workerTerminate }] = useWorker(fn,
],
});
```
<!--
## Local Dependencies Example
```javascript
Expand All @@ -74,6 +75,7 @@ const [workerFn, {status: workerStatus, kill: workerTerminate }] = useWorker(fn,
localDependencies: () => [expensiveAdder] // we pass the local function to the worker
});
```
-->

:::tip
To see an example click here: [ExternalScripts](https://github.com/alewin/useWorker/blob/develop/example/src/pages/ExternalScripts/index.js)
Expand Down
6 changes: 0 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9bd4ebc

Please sign in to comment.