forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
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 (facebook#42717)
Summary: Pull Request resolved: facebook#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: ff469fea3ff78e6bceb79baaa19d9654eb6bbf0b
- Loading branch information
1 parent
3a789a1
commit 2372461
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 (moduleOrFactory instanceof Function) { | ||
global.RN$registerCallableModule(name, moduleOrFactory); | ||
return; | ||
} | ||
|
||
global.RN$registerCallableModule(name, () => moduleOrFactory); | ||
}; | ||
} | ||
|
||
const BatchedBridge = require('../BatchedBridge/BatchedBridge'); | ||
return (name, moduleOrFactory) => { | ||
if (moduleOrFactory instanceof 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