react-native-worklets-core
react-native-worklets-core copied to clipboard
return value from worklets
- object spread is not working
- array is converted to object
// from worklets
export workletFun = createRunInContextFn(() => {
'worklet';
return {test_arr: [1,2]};
})
// rn js
// array is converted to object
const { test_arr } = await workletFun();
console.log(test_arr);
// {"0": 1, "1": 2 }
// object spread not working
const res = await workletFun();
console.log({...res, a: 1})
same problem
the resulting values are Proxies. Arrays and Objects are Proxied as native HostObjects, so they can cheaply be shared by reference, without copying them.
Methods such as map
, accessing index, etc all still work.
Is there any reason you need them to be an Array/Object instead of a Proxy?
Object spread not working could be a feature request yep
@mrousavy I want to pass the resulting values into native module then I got an error "TypeError: ownKeys target key is non-configurable but not present in trap result"
I don't know, never seen that error before and don't have a stacktrace or repro so I can't help you
You can simply pass result type Array from worklet into android native module as ReadonlyArray and see what happen @mrousavy