Skip to content

CodeGen Discussion #92

@kelset

Description

@kelset

Intro

With this issue I'd like to try and create a "one stop" for all the information available around the CodeGen: a tool to "automate" the compatibility between JS and native side. By using statically typed Javascript this tool can generate the interface files needed by Fabric and TurboModules - so that they know what will be send across the realms with confidence.
As @shergin said: "The biggest benefit of Codegen is not just type-safety, it's compile time type-safety. That means the code counterparts from both worlds can trust each other without any runtime checks, which means smaller code size and faster execution (less to load & less to execute)".

Terminology

  • Fabric: just the UI layer re-architecture, to take full advantage of concurrent React architecture. (dedicated issue)
  • TurboModules: re-architecture of NativeModules, also using JSI. (dedicated issue)
  • JSI: JavaScript Interface, it's a unified lightweight general purpose API for (theoretically) any JavaScript virtual machine. It enables every other piece of the re-architecture. (dedicated issue)

TL;DR

From @axe-fb's blogpost, here's a temporary description of the CodeGen (please consider that this is not yet finalised, it may change in the future)

In both TurboModule and Fabric, interface available to JavaScript could be defined using Flow (or TypeScript). We can further leverage this interface definition to generate many of the C++ classes, and the interfaces/protocols for Java/ObjC implementations. For example, in case of TurboModules, the C++ class that wraps the Java/ObjC class and exposes the methods using a JSI object can be generated.
This will ensure that all JavaScript calls have implementations available on the native side, and will continue to ensure this with over the air updates like code push.

Available Materials

@TheSavior did an in-depth Twitch stream to explain the purpose of CodeGen.

@kelset wrote about it in part 1 of his blogpost series about the new architecture - and did a talk about the whole rearchitecture in April 2019 at React Edinburgh.

@kelset also did a more in-depth talk at React Advanced London in Oct 2019: youtube recording & slides.

Q&A

This is also a place for questions related to this effort and its direction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    👓 TransparencyThis label identifies a subject on which the core has been already discussing prior to the repo

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions