Skip to content

Commit 4b1aeff

Browse files
fix: remove isTurboModuleEnabled check from docs (facebook#3337)
* fix: remove isTurboModuleEnabled check * fix: remove unnecessary back ticks Co-authored-by: Riccardo <[email protected]> Co-authored-by: Riccardo <[email protected]>
1 parent 9987b07 commit 4b1aeff

File tree

2 files changed

+6
-62
lines changed

2 files changed

+6
-62
lines changed

docs/the-new-architecture/backward-compatibility-turbomodules.md

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ For a Turbo Native Module, the source of truth is the `Native<MyModule>.js` (or
347347
import MyModule from 'your-module/src/index';
348348
```
349349

350-
The **goal** is to conditionally `export` the proper object from the `index` file , given the architecture chosen by the user. We can achieve this with a code that looks like this:
350+
Since `TurboModuleRegistry.get` taps into the old Native Modules API under the hood, we need to re-export our module, to avoid registering it multiple times.
351351

352352
<Tabs groupId="turbomodule-backward-compatibility"
353353
defaultValue={constants.defaultTurboModuleSpecLanguage}
@@ -356,43 +356,15 @@ The **goal** is to conditionally `export` the proper object from the `index` fil
356356

357357
```ts
358358
// @flow
359-
360-
import { NativeModules } from 'react-native'
361-
362-
const isTurboModuleEnabled = global.__turboModuleProxy != null;
363-
364-
const myModule = isTurboModuleEnabled ?
365-
require('./Native<MyModule>').default :
366-
NativeModules.<MyModule>;
367-
368-
export default myModule;
359+
export default require('./Native<MyModule>').default;
369360
```
370361

371362
</TabItem>
372363
<TabItem value="TypeScript">
373364

374365
```ts
375-
const isTurboModuleEnabled = global.__turboModuleProxy != null;
376-
377-
const myModule = isTurboModuleEnabled
378-
? require('./Native<MyModule>').default
379-
: require('./<MyModule>').default;
380-
381-
export default myModule;
366+
export default require('./Native<MyModule>').default;
382367
```
383368

384369
</TabItem>
385370
</Tabs>
386-
387-
:::note
388-
If you are using TypeScript and you want to follow the example, ensure to `export` the `NativeModule` in a separate `ts` file called `<MyModule>.ts`.
389-
:::
390-
391-
Whether you are using Flow or TypeScript for your specs, we understand which architecture is running by checking whether the `global.__turboModuleProxy` object has been set or not.
392-
393-
:::caution
394-
The `global.__turboModuleProxy` API may change in the future for a function that encapsulates this check.
395-
:::
396-
397-
- If that object is `null`, the app has not enabled the Turbo Native Module feature. It's running on the Old Architecture, and the fallback is to use the default [`Legacy Native Module` implementation](../native-modules-intro).
398-
- If that object is set, the app is running with the Turbo Native Modules enabled, and it should use the `Native<MyModule>` spec to access the Turbo Native Module.

website/versioned_docs/version-0.70/the-new-architecture/backward-compatibility-turbomodules.md

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ For a Turbo Native Module, the source of truth is the `Native<MyModule>.js` (or
332332
import MyModule from 'your-module/src/index';
333333
```
334334

335-
The **goal** is to conditionally `export` from the `index` file the proper object, given the architecture chosen by the user. We can achieve this with a code that looks like this:
335+
Since `TurboModuleRegistry.get` taps into the old Native Modules API under the hood, we need to re-export our module, to avoid registering it multiple times.
336336

337337
<Tabs groupId="turbomodule-backward-compatibility"
338338
defaultValue={constants.defaultTurboModuleSpecLanguage}
@@ -341,43 +341,15 @@ The **goal** is to conditionally `export` from the `index` file the proper objec
341341

342342
```ts
343343
// @flow
344-
345-
import { NativeModules } from 'react-native'
346-
347-
const isTurboModuleEnabled = global.__turboModuleProxy != null;
348-
349-
const myModule = isTurboModuleEnabled ?
350-
require('./Native<MyModule>').default :
351-
NativeModules.<MyModule>;
352-
353-
export default myModule;
344+
export default require('./Native<MyModule>').default;
354345
```
355346

356347
</TabItem>
357348
<TabItem value="TypeScript">
358349

359350
```ts
360-
const isTurboModuleEnabled = global.__turboModuleProxy != null;
361-
362-
const myModule = isTurboModuleEnabled
363-
? require('./Native<MyModule>').default
364-
: require('./<MyModule>').default;
365-
366-
export default myModule;
351+
export default require('./Native<MyModule>').default;
367352
```
368353

369354
</TabItem>
370355
</Tabs>
371-
372-
:::note
373-
If you are using TypeScript and you want to follow the example, make sure to `export` the `NativeModule` in a separate `ts` file called `<MyModule>.ts`.
374-
:::
375-
376-
Whether you are using Flow or TypeScript for your specs, we understand which architecture is running by checking whether the `global.__turboModuleProxy` object has been set or not.
377-
378-
:::caution
379-
The `global.__turboModuleProxy` API may change in the future for a function that encapsulate this check.
380-
:::
381-
382-
- If that object is `null`, the app has not enabled the Turbo Native Module feature. It's running on the Old Architecture, and the fallback is to use the default [`Legacy Native Module` implementation](../native-modules-intro).
383-
- If that object is set, the app is running with the Turbo Native Modules enabled, and it should use the `Native<MyModule>` spec to access the Turbo Native Module.

0 commit comments

Comments
 (0)