react-native-worklets-core icon indicating copy to clipboard operation
react-native-worklets-core copied to clipboard

return value from worklets

Open cbjs opened this issue 1 year ago • 6 comments

  1. object spread is not working
  2. 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})

cbjs avatar Sep 25 '23 01:09 cbjs

same problem

linhttbk97 avatar Sep 27 '23 08:09 linhttbk97

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?

mrousavy avatar Oct 06 '23 14:10 mrousavy

Object spread not working could be a feature request yep

mrousavy avatar Oct 06 '23 14:10 mrousavy

@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"

linhttbk97 avatar Oct 13 '23 09:10 linhttbk97

I don't know, never seen that error before and don't have a stacktrace or repro so I can't help you

mrousavy avatar Oct 13 '23 10:10 mrousavy

You can simply pass result type Array from worklet into android native module as ReadonlyArray and see what happen @mrousavy

linhttbk97 avatar Oct 16 '23 04:10 linhttbk97