Skip to content

Commit

Permalink
Revise the suggestion for using goog.require in native.js files
Browse files Browse the repository at this point in the history
 - removed the tip about ensuring it's import in Java. This won't always work
 - Focus more toward the potential for conflicting names and incorrect loading semantics (IIRC this is a problem with cyclical references).
 - Instead suggest people just implement a class in JS and use JsInterop.

PiperOrigin-RevId: 694314634
  • Loading branch information
kevinoconnor7 authored and copybara-github committed Nov 8, 2024
1 parent 9699a29 commit db50e64
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions docs/native-js-sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ Foo.getValue = function() {

* **DO NOT** add extra goog.requires to `native.js` files. Since these are
concatenated with the transpiled code for the rest of the file, this is
effectively putting import in the middle of the file. Additionally, the
imports you add may conflict with existing imports.
effectively putting imports in the middle of the file. Additionally, the
imports you add may conflict with existing imports or cause incorrect
loading semantics, both of which will be confusing to debug.

Instead, ensure the Java code has imports for all the types you'll need.
These imports will be accessible in the `native.js` by referencing their
simple names.
Generally if you get to the point of having to do this, you're better off
writing the code separately in JS and
[using JsInteorp to call it](jsinterop-by-example.md#jstype-interface-with-closure-utilities).

* Be particularly mindful of nullability in `native.js` files. The JSCompiler
does not enforce nullability checks within J2CL-generated code, and since
Expand Down

0 comments on commit db50e64

Please sign in to comment.