Closed mrousavy closed 7 months ago
@chrfalch some questions;
worklet(...)
call? That way users could do:
const func = worklet(() => {
return "this is a worklet, without the directive!"
})
...and skip adding the 'worklet'
directive in these cases..
__location
and asString
and stuff...
Adds the
worklet(...)
andisWorklet(..)
functions:worklet(...)
This will do some runtime checking to ensure the given function is a worklet (uses
__initData
,__closure
and__workletHash
) and throws with some useful debugging information if it isn't.I will use this in VisionCamera's
useFrameProcessor
function to make sure people pass in worklets (funcs with'worklet'
directive) and they installed the babel plugin properly. Otherwise the error is a bit cryptic, with this it's more clear what went wrong:Also, the returned type is useful because you can now safely access
func.__workletHash
orfunc.__closure
.isWorklet(...)
Same thing as
worklet(...)
, but only returns false if the function is not a worklet instead of throwing an error.Changes to
useWorklet(..)
The
useWorklet
hook now usesworklet(..)
underneath to ensure the user passed in a correct Worklet.Also, I now removed the
dependencies
parameter by automatically using the values infunc.__closure
for theuseMemo
's dependencies. This is pretty cool because people often forgot to the hook dependencies inuseFrameProcessor
and wondered why it didn't update/re-build after a re-render.