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

Multiples Components best practices: sharing bridge? #1073

Closed
finalquest opened this issue Apr 30, 2015 · 10 comments
Closed

Multiples Components best practices: sharing bridge? #1073

finalquest opened this issue Apr 30, 2015 · 10 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@finalquest
Copy link

Hi again.
The context first:

Im using RN as the V in MVC. I've created a JS with a RN component, created a UIView in the obj-c side, and use a RCTRootView (initWithBridge) as a subview.
Everything works fine.

Now the question.
Suppose that I have a two RN components, in two JS files (DetailView.js, SomeOtherView.js).
Is there a way to make a single JS file with the 2 components, so I can use only one bridge and share it. I dont really understand how can I achieve this, and use initWithBridge: moduleName:

Sorry if is a super noob question.
Thanks and regards

@nicklockwood
Copy link
Contributor

Yes, you can create the bridge using

RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL: moduleProvider: launchOptions:];

Then store that in a property somewhere (e.g. in your AppDelegate), and whenever you need to create a root view, say:

RCTRootView *rootView = [[RCTRootView alloc] initWithBridge: moduleName:];

That way the JS code bundle is shared, and each root view runs its own component.

@finalquest finalquest changed the title Multiples Components best practices: sharing bride? Multiples Components best practices: sharing bridge? Apr 30, 2015
@finalquest
Copy link
Author

Hi. thanks for the response.
What I dont really get it yet is how I can put multiple JS files in one single bundle?
Where every JS file is an independent component

@ssssssssssss
Copy link

Please see these two issues, it should address your previous question.
Best practice to integrate existing app with React-Native #995
Forcing view refresh #1049

@brentvatne
Copy link
Collaborator

@finalquest - react-native bundle will do that for you, if you have any questions that aren't answered by this thread or the issues that @ssssssssssss mentioned let me know, closing until then

@dolmens
Copy link

dolmens commented May 9, 2015

hey guys, if i take it correctly, if i want to share the same bridge, then i need to bundle all the js files/functions to a big bundle, right? is there a way that i can still share the bridge but download every module every single time?

@brentvatne
Copy link
Collaborator

@dolmens - what's your use case?

@dolmens
Copy link

dolmens commented May 9, 2015

@brentvatne say i choose to place the js bundle on server side, and i have many react views, named v1, v2, ..., etc., corresponding to js module m1, m2, ..., etc., and i want to download these modules on demand, in other words, i don't download them only until i show the corresonding views.

@brentvatne
Copy link
Collaborator

@dolmens - Ah, interesting. As far as I know, this is not supported at the moment, but @tadeuzagallo or @ide would know better than I

@tadeuzagallo
Copy link
Contributor

Yeah, @brentvatne is right, it's not possible yet... The bridge holds where to require the javascript bundle, the RootView just knows which module to require, but it has to be previously loaded by the bridge.

@grittymindy
Copy link

@brentvatne can you give some more details about how to put multiple JS files into a single bundle, using react-native bundle?

@facebook facebook locked as resolved and limited conversation to collaborators May 29, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

8 participants