-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate BatchedBridge.registerCallableModule (#42717)
Summary: Pull Request resolved: #42717 This diff introduces a new bridge/bridgeless-agnostic api for registering JavaScript modules with React Native. Usage: ``` import {registerCallableModule} from 'react-native'; registerCallableModule('FooModule', () => {...}); registerCallableModule('BarModule', {...}); ``` Changelog: [General][Deprecated] - Deprecate BatchedBridge.registerCallableModule. Please use registerCallableModule instead Reviewed By: javache Differential Revision: D52805387 fbshipit-source-id: c7e77f0450ce1b0de349fa540c3a812256da054f
- Loading branch information
1 parent
daa3080
commit 7f549ec
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/react-native/Libraries/Core/registerCallableModule.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
type Module = {...}; | ||
type RegisterCallableModule = ( | ||
name: string, | ||
moduleOrFactory: Module | (void => Module), | ||
) => void; | ||
|
||
const registerCallableModule: RegisterCallableModule = (function () { | ||
if (global.RN$Bridgeless === true) { | ||
return (name, moduleOrFactory) => { | ||
if (typeof moduleOrFactory === 'function') { | ||
global.RN$registerCallableModule(name, moduleOrFactory); | ||
return; | ||
} | ||
|
||
global.RN$registerCallableModule(name, () => moduleOrFactory); | ||
}; | ||
} | ||
|
||
const BatchedBridge = require('../BatchedBridge/BatchedBridge'); | ||
return (name, moduleOrFactory) => { | ||
if (typeof moduleOrFactory === 'function') { | ||
BatchedBridge.registerLazyCallableModule(name, moduleOrFactory); | ||
return; | ||
} | ||
|
||
BatchedBridge.registerCallableModule(name, moduleOrFactory); | ||
}; | ||
})(); | ||
|
||
export default registerCallableModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters