Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return value from worklets #120

Open
cbjs opened this issue Sep 25, 2023 · 6 comments
Open

return value from worklets #120

cbjs opened this issue Sep 25, 2023 · 6 comments

Comments

@cbjs
Copy link

cbjs commented Sep 25, 2023

  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})
@linhttbk97
Copy link

same problem

@mrousavy
Copy link
Member

mrousavy commented Oct 6, 2023

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
Copy link
Member

mrousavy commented Oct 6, 2023

Object spread not working could be a feature request yep

@linhttbk97
Copy link

linhttbk97 commented Oct 13, 2023

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

@mrousavy
Copy link
Member

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

@linhttbk97
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants