react-native-threads icon indicating copy to clipboard operation
react-native-threads copied to clipboard

[Question] Using a thread worker written in TypeScript

Open omatrot opened this issue 5 years ago • 9 comments

I'm using Typescript and a worker thread using a lot of modules. I guess I should take the release route even for development to produce a correct javascript file to be used by this library. Am I wrong?

omatrot avatar Mar 13 '19 16:03 omatrot

I'll be on the same page soon when I switch to TS. If you figure this out it'd be great if someone could add it to the readme :)

cjroth avatar Mar 13 '19 17:03 cjroth

Have you done it with Javascript with multiple files or only one file containing all the business logic? Are you using native modules? I've managed to give it a javascript file but it is failing with a red screen telling me that

'DeviceInfo native module is not installed' DeviceInfo.js: 17:10

This file is here: ./node_modules/react-native/Libraries/Utilities/DeviceInfo.js

omatrot avatar Mar 13 '19 17:03 omatrot

I'm using native modules and multiple JS files on iOS but I have not tried Android. The readme has instructions for setting up native modules with Android which requires an additional step. It sounds like you may need to do that.

cjroth avatar Mar 13 '19 17:03 cjroth

I've seen that and used it already. The problem is that DeviceInfo is a React Native module !

omatrot avatar Mar 13 '19 17:03 omatrot

No idea then. I know there's a community version of DeviceInfo as it's one of the modules they are working on breaking out from the core. Maybe you need to include it anyways?

On Wed, Mar 13, 2019 at 1:57 PM Olivier MATROT [email protected] wrote:

I've seen that and used it already. The problem is that DeviceInfo is a React Native module !

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/joltup/react-native-threads/issues/67#issuecomment-472537081, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjh8sIt23fArOooO9kDLqFxlUucnXwTks5vWTwDgaJpZM4btmiy .

-- Chris Roth cjroth.com http://www.cjroth.com

cjroth avatar Mar 13 '19 18:03 cjroth

It is a packager problem, there is a request to the 'thread.js' file to bundle it. It seems to me that my file is somehow invalid for the bundler which may not be able to require the modules correctly... How do you import your dependencies at the top of your .js thread file?

omatrot avatar Mar 13 '19 18:03 omatrot

Oops I missed your last comment. Yeah, I just import everything at the top of my js thread file. Importing works just the same as it does in the main RN JS thread though. It's basically a parallel universe.

Were you able to get TS working with the thread? I'm starting to look into moving over to it now.

cjroth avatar May 09 '19 17:05 cjroth

Did you guys find a way to solve this?

genesy avatar Dec 12 '19 07:12 genesy

is it possible to run a string encoded js bundle instead of a file name?

that way one could transpile TS and generate a big chungus JS bundle to run in the worker

lucasew avatar Jul 30 '22 01:07 lucasew