Skip to content

Commit

Permalink
fix: remove isTurboModuleEnabled check from docs (facebook#3337)
Browse files Browse the repository at this point in the history
* fix: remove isTurboModuleEnabled check

* fix: remove unnecessary back ticks

Co-authored-by: Riccardo <riccardo.cipolleschi@gmail.com>

Co-authored-by: Riccardo <riccardo.cipolleschi@gmail.com>
  • Loading branch information
okwasniewski and cipolleschi committed Oct 3, 2022
1 parent 9987b07 commit 4b1aeff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 62 deletions.
34 changes: 3 additions & 31 deletions docs/the-new-architecture/backward-compatibility-turbomodules.md
Expand Up @@ -347,7 +347,7 @@ For a Turbo Native Module, the source of truth is the `Native<MyModule>.js` (or
import MyModule from 'your-module/src/index';
```

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:
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.

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

```ts
// @flow

import { NativeModules } from 'react-native'

const isTurboModuleEnabled = global.__turboModuleProxy != null;

const myModule = isTurboModuleEnabled ?
require('./Native<MyModule>').default :
NativeModules.<MyModule>;

export default myModule;
export default require('./Native<MyModule>').default;
```

</TabItem>
<TabItem value="TypeScript">

```ts
const isTurboModuleEnabled = global.__turboModuleProxy != null;

const myModule = isTurboModuleEnabled
? require('./Native<MyModule>').default
: require('./<MyModule>').default;

export default myModule;
export default require('./Native<MyModule>').default;
```

</TabItem>
</Tabs>

:::note
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`.
:::

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.

:::caution
The `global.__turboModuleProxy` API may change in the future for a function that encapsulates this check.
:::

- 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).
- 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.
Expand Up @@ -332,7 +332,7 @@ For a Turbo Native Module, the source of truth is the `Native<MyModule>.js` (or
import MyModule from 'your-module/src/index';
```

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:
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.

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

```ts
// @flow

import { NativeModules } from 'react-native'

const isTurboModuleEnabled = global.__turboModuleProxy != null;

const myModule = isTurboModuleEnabled ?
require('./Native<MyModule>').default :
NativeModules.<MyModule>;

export default myModule;
export default require('./Native<MyModule>').default;
```

</TabItem>
<TabItem value="TypeScript">

```ts
const isTurboModuleEnabled = global.__turboModuleProxy != null;

const myModule = isTurboModuleEnabled
? require('./Native<MyModule>').default
: require('./<MyModule>').default;

export default myModule;
export default require('./Native<MyModule>').default;
```

</TabItem>
</Tabs>

:::note
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`.
:::

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.

:::caution
The `global.__turboModuleProxy` API may change in the future for a function that encapsulate this check.
:::

- 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).
- 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 comments on commit 4b1aeff

Please sign in to comment.