You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The text was updated successfully, but these errors were encountered:
brentvatne
changed the title
is it possible to get JavaScriptCore's JSContext somehow?
[Bridge] is it possible to get JavaScriptCore's JSContext somehow?
Jun 15, 2015
@plandem It's not very well supported at the moment. You will have issues with React's event loop if the JS functions you invoke directly from Obj-C do any kind of async work. Directly using the JSContext will bypass the code path that React takes to start an iteration of its event loop. Also if your JS throws an unhandled error you may have to handle it yourself. And even though JSC is mostly thread-safe, you should make sure to use the JSContext only on the same JS thread as the one that React will use.
But since you asked... currently the best approach is to subclass RCTContextExecutor and define init to return -[super initWithJavaScriptThread:globalContextRef:], which allows you to inject your own JSContextRef as the second argument. Expose this JSContext/JSContextRef to the rest of your app via NSNotificationCenter or a global variable. Then set up an RCTBridge like so:
RCTBridge*bridge=[RCTBridgealloc];// warranty not includedbridge.executorClass=[YourCustomExecutorclass];bridge=[bridgeinitWithBundleURL:urlmoduleProvider:nillaunchOptions:launchOptions];RCTRootView*root=[[RCTRootViewalloc]initWithBridge:bridgemoduleName:@"YourAppKey"];
I'm going to close this because as you can see it's really not well-supported but it does work if you know what you're doing and are willing to dive into the full stack.
Thanks, for help. Yes, i have reasons to use it. It's not for any heavy tasks/async and etc. In my case i just need to move some 'value formatters' to JS side, because some visual parts will be there. But in other cases i will need just 'value formatters' without any visual parts. So i want to use same way - formatters from JS. It's mostly native app and only some parts ("modules") in React
facebook
locked as resolved and limited conversation to collaborators
Jun 16, 2018
Why do i need it? Sometimes i just want to use javascript directly and don't create wrappers to emit events to/from JS to get values.
For example, i would like to get value from 'SimpleApp.prototype.validate'. Just want to call it directly.
In my case, i have one bundle with visuals and some functions that has no any connection to visual part. Right now we have only:
and call it from objective-c:
But current implementation does not allow to get value from js. So my question again - is it possible to get JSContext to do next:
The text was updated successfully, but these errors were encountered: