taro icon indicating copy to clipboard operation
taro copied to clipboard

支持小程序的 worklet 类型函数定义

Open Char-set opened this issue 1 year ago • 4 comments

这个特性解决了什么问题?

微信小程序skyline渲染引擎,自定义路由功能需要用到该类型函数

官方定义【自定义路由】:https://developers.weixin.qq.com/miniprogram/dev/framework/runtime/skyline/custom-route.html

worklet 类型函数:https://developers.weixin.qq.com/miniprogram/dev/framework/runtime/skyline/worklet.html#worklet-%E5%87%BD%E6%95%B0%E5%AE%9A%E4%B9%89

这个 API 长什么样?

function helloWorklet() {
    'worklet'; //'worklet'声明该函数为work函数,可以在js线程和UI线程中调用
    console.log('hello worklet');
}

useEffect(() => {
        wx.worklet.runOnUI(helloWorklet)();
}, []);

目前会报警告 :“The parameter to runOnUI should be a worklet function”

同时 helloWorklet 函数 并不是 worklet 类型

Char-set avatar Nov 28 '23 11:11 Char-set

请问现在支持了吗?

wangjq4214 avatar Apr 27 '24 13:04 wangjq4214

function helloWorklet() {
    'worklet'; //'worklet'声明该函数为work函数,可以在js线程和UI线程中调用
    console.log('hello worklet');
}

useEffect(() => {
        wx.worklet.runOnUI(helloWorklet)();
}, []);

我的3.20版本可用,没报错

codedart2018 avatar May 07 '24 06:05 codedart2018

 'worklet'
function helloWorklet() {
    'worklet'; //'worklet'声明该函数为work函数,可以在js线程和UI线程中调用
    console.log('hello worklet');
}

useEffect(() => {
        wx.worklet.runOnUI(helloWorklet)();
}, []);

我的3.20版本可用,没报错

'worklet' 字符串在生产环境中打包,会被terser-webpack-plugin插件给干掉,你是如何保留的啊

Luobinf avatar Jun 26 '24 14:06 Luobinf