-
Notifications
You must be signed in to change notification settings - Fork 61
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
Typescript Module initialization #588
Comments
Yes! (1) When:This is important as otherwise on start up of any application that may directly or indirectly be installing Consider the following scenario where Babylon is being consumed not by an application, but by a library that is being shipped to N react-native applications. Let's call the library X. Performing initialization globally forces all N applications consuming X to have to support and install the native module ( (2) How:Performing a global init is disallowing you from supporting anything to the effect of "initialization configuration" in a clean and extensible manner. For instance, consider the case where Babylon has support for XR functionalities that it wants to initialize as part of the overall initialization. A consuming library or application does not care about XR at all and wants to skip all of that workload (either to speed things up or work around a crash/freeze that XR init is causing for them for unrelated reasons). This will unfortunately likely require you to break versions as changing the behavior to "no longer initialized on startup of application and must manually call |
I think we should try hard not to introduce required Babylon React Native specific APIs (like useModuleInitializer). BRN has only two required APIs right now, useEngine and EngineView, and they are intended to not be specific to React Native. The original idea was that we would move the two APIs to a new @babylonjs/react package that could be used in the browser with React.js. Then if you have a React.js web app using useEngine and EngineView from @babylonjs/react, you can bring that web app code directly to React Native and just add the @babylonjs/react-native packages, but not have to make any code changes. This moves the code portability up another layer (from just the core babylonjs API to the React integration). Having React Native specific APIs makes this goal harder to achieve. |
For what it's worth the bulk of my recommendation here is focusing more on "let's not global init" and not necessarily putting too much of a focus on how to do it instead. I see it as totally okay to put all of this behind a plain JavaScript class that can be reused in or out of React or React Native. The React / React Native consumer can simply instantiate the class, assign it as sole value of a |
ensureInitialized
is global meaning it's impossible to user to not initialize BRN.BabylonReactNative/Modules/@babylonjs/react-native/EngineHook.ts
Line 75 in aafbad8
Partner needs more control on this.
The text was updated successfully, but these errors were encountered: