taro
taro copied to clipboard
支持小程序的 worklet 类型函数定义
这个特性解决了什么问题?
微信小程序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 类型
请问现在支持了吗?
function helloWorklet() { 'worklet'; //'worklet'声明该函数为work函数,可以在js线程和UI线程中调用 console.log('hello worklet'); } useEffect(() => { wx.worklet.runOnUI(helloWorklet)(); }, []);
我的3.20版本可用,没报错
'worklet'
function helloWorklet() { 'worklet'; //'worklet'声明该函数为work函数,可以在js线程和UI线程中调用 console.log('hello worklet'); } useEffect(() => { wx.worklet.runOnUI(helloWorklet)(); }, []);
我的3.20版本可用,没报错
'worklet' 字符串在生产环境中打包,会被terser-webpack-plugin插件给干掉,你是如何保留的啊