turbox3d/turbox

装饰器基于最新proposal会导致报错

Closed this issue · 1 comments

基于最新babel/plugin-proposal-decorators设定version: '2023-01'后,@reactor会出现Object.defineProperty called on non-object 错误

decorator的提案一直不稳定,且存在破坏性变更,后续稳定了再彻底更新一波。
虽然turbox已经尽量做到0依赖(为了避免时间久了框架腐烂维护不动),但reactivity-react还是会依赖react,three和pixi相关的上层框架也会依赖,整体当然会依赖ts,还是会有语法上的兼容微调需要跟(但核心代码不会被影响,reactivity和renderer-core非常稳定)
解决办法:
1.建议使用旧版提案
2.不使用装饰器,使用函数API包裹

// plain object
const obj = reactor<ObjInterface>({
  test: {
    a: 111111,
    b: 222222,
  },
  xxx: 'reactor xxx',
});
// 数组
const array = reactor<Array<string>>(['111']);
// 集合 Map、Set、WeakMap、WeakSet
const map = reactor<Map<string, string>>(new Map());

reactive(() => {
  console.log(rct.test.a);
});
const f = mutation('customName', async () => {
  await doSomething();
}, {
  immediately: false,
  displayName: '自定义名称',
  forceSaveHistory: false,
  isNeedRecord: true,
});
await f();