Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend useWebWorkerFn to also accept an array of local dependencies #2005

Closed
4 tasks done
Evertt opened this issue Jul 27, 2022 · 3 comments · May be fixed by #3899
Closed
4 tasks done

Extend useWebWorkerFn to also accept an array of local dependencies #2005

Evertt opened this issue Jul 27, 2022 · 3 comments · May be fixed by #3899
Labels
enhancement New feature or request

Comments

@Evertt
Copy link

Evertt commented Jul 27, 2022

Clear and concise description of the problem

useWebWorkerFn provides an option called dependencies in which you can give an array of strings that are paths to javascript files that the web worker will then import so that it can use any variables and functions that are globally defined in those javascript files.

However, often times you already have some functions in your local scope and it would be much more convenient to be able to just provide an array of references to those functions in an option called localDependencies.

So it might look something like this:

import { useWebWorkerFn } from '@vueuse/core'
import { expensiveAdder } from './utils'

const { workerFn, workerStatus, workerTerminate } = useWebWorkerFn(
  (a, b) => expensiveAdder(a,b),
  {
    timeout: 50000,
    localDependencies: () => [expensiveAdder], // we pass the local function to the worker
  },
)

Suggested solution

According to the docs useWebWorkerFn is a port from Alessio Koci's useWorker, which according to its docs allows the developer to provide an array of references to local functions so that they can be used inside the worker.

This is different from the externalDependencies option (which vueuse has renamed to dependencies) that already exists, because then you really need to create a separate file for that function and then provide it using the path to that file. The localDependencies option is just way more convenient in many cases.

And from what I understand, Alessio Koci also didn't create this feature himself, but that it ultimately comes from Arjun Barrett's isoworker.

So basically my request is, can you please copy that feature into useWebWorkerFn? And maybe, if you're gonna add an option called localDependencies, then I would deprecate the dependencies and rename it to externalDependencies.

Alternative

I can't think of an alternative other than just keeping everything as it is now... Like it isn't impossible to do certain things without this localDependencies option, it's just less convenient.

Additional context

No response

Validations

@Evertt Evertt added the enhancement New feature or request label Jul 27, 2022
@stale
Copy link

stale bot commented Sep 26, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 26, 2022
@stale stale bot closed this as completed Oct 3, 2022
@gjfLeo
Copy link

gjfLeo commented Nov 1, 2022

Hello, I went to the same problem. Is there any solution now? Thanks.

@Redemption198
Copy link
Contributor

Bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants