You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 docsuseWebWorkerFn 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.
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.
Clear and concise description of the problem
useWebWorkerFn
provides an option calleddependencies
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:
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 todependencies
) 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. ThelocalDependencies
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 calledlocalDependencies
, then I would deprecate thedependencies
and rename it toexternalDependencies
.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
The text was updated successfully, but these errors were encountered: