@lynx-js/react / built-in-macros
Built-in Macros
The @lynx-js/react package processes built-in macro definitions such as __BACKGROUND__ and __MAIN_THREAD__. During compilation, code blocks with false conditions are automatically removed.
__BACKGROUND__
- Type:
boolean - Purpose: Controls code execution in background thread environment. Used to determine which code segments should be preserved in background thread code after compilation.
Usage Examples
In Function Components
Here's an example using the App component:
After compilation, this code is transformed into:
- Background thread code (
background.jsin the compilation intermediate directory):
- Main thread code (
main-thread.jsin the compilation intermediate directory):
In Class Components
Here's an example using the Conversations component:
After compilation, this code is transformed into:
- Background thread code (
background.jsin the compilation intermediate directory):
- Main thread code (
main-thread.jsin the compilation intermediate directory):
__MAIN_THREAD__
- Type:
boolean - Purpose: Controls code execution in main thread environment. Used to determine which code segments should be preserved in main thread code during compilation.
Usage Examples
In Function Components
Here's an example using the App component:
After compilation, this code is transformed into:
- Background thread code (
background.jsin the compilation intermediate directory):
- Main thread code (
main-thread.jsin the compilation intermediate directory):
In Class Components
Here's an example using the Conversations component:
After compilation, this code is transformed into:
- Background thread code (
background.jsin the compilation intermediate directory):
- Main thread code (
main-thread.jsin the compilation intermediate directory):
__JS__
- Type:
boolean - Purpose: Alias of
__BACKGROUND__.
Deprecated
Use __BACKGROUND__ instead.
__LEPUS__
- Type:
boolean - Purpose: Alias of
__MAIN_THREAD__.
Deprecated
Use __MAIN_THREAD__ instead.
__DEV__
- Type:
boolean - Purpose:
truein development builds,falsein production. Use it to guard development-only code — prop validation, invariant checks, friendlier error messages — so none of it reaches production.
__PROFILE__
- Type:
boolean - Purpose:
truewhen the build carries profiling instrumentation. It is on by default in development and off in production. See Performance Profiling for the traces it produces, and Runtime Profiling for how to turn it on for a production build.
__REACT_DEVTOOL__
- Type:
boolean | undefined - Purpose:
truewhen the runtime hooks that Preact DevTools depends on are compiled in. Enabled by default in development; in production it can be enabled with theREACT_DEVTOOL=trueenvironment variable.
__LAZY_BUNDLE_FETCHER__
- Type:
'FetchBundle' | 'QueryComponent' - Purpose: Which lazy bundle fetcher the build is wired up to.
'FetchBundle'enables thelynx.fetchBundle-based path (andimport(..., { with: { mode } })mode hints);'QueryComponent'is the legacylynx.QueryComponentpath. How the value is selected, theREACT_LAZY_BUNDLE_FETCHERoverride and the version scope are documented in Lazy bundle loaders.