Giter VIP home page Giter VIP logo

Comments (3)

frantic avatar frantic commented on March 29, 2024

I think it's a very clever idea and I like reducing RCTJavaScriptExecutor protocol. However, the code in the bundle has to define a global require function that will be used by ObjC to invoke JS methods. Also there are benefits for the existing model, for example Chrome debugger integration (not in the oss repo yet) that runs the JS code in a Chrome page. The app bundle in this case is loaded via <script> tag instead of being passed via websockets.

from react-native.

ide avatar ide commented on March 29, 2024

Could the JS application engine be set up by passing in a global object? For example:

(function(global) {
  // Make require.js use "global", which passes it to all of the module factory functions.
  // require.js also sets "global.require", "global.requireLazy", etc...
});

From the native side, the application engine is initialized like:

// Create a "global" object. May need to have it act as a proxy to the real global object
// and would need to write a little more code for that.
JSValue *reactGlobal = [JSValue valueWithNewObjectInContext:context];
reactGlobal[@"__fbBatchedBridgeConfig"] = bridgeConfigDictionary;
[[context evaluateScript:bundleScriptString] callWithArguments:@[reactGlobal]];

Accessing the global require function from Obj-C is simple as well:

JSValue *exports = [reactGlobal[@"require"] callWithArguments:@[@"moduleName"]];
[exports invokeMethod:@"doSomething" withArguments:@[...]];

So in the end, RCTJavaScriptExecutor has a smaller API and ReactKit is better encapsulated by reducing pollution of the global scope (some functions like setTimeout need another approach though).


For the Chrome debugger extension, it might be possible to keep using the real global object with the help of the packager by serving (function(global) { /* ... */ })(window);.

from react-native.

sahrens avatar sahrens commented on March 29, 2024

Closing for now since it doesn't sound like this is blocking anything.

from react-native.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.