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.
feat[DebuggingRegistry]: basic implementation (facebook#41743)
Summary: Changelog: [Internal] There will be a single DebuggingRegistry instance per runtime, which will be responsible for finding lowest AppContainer ancestor for highligthed component. It will receive refs to root views (ancestors, AppContainers) as subscriptions and later will call all necessary methods. In the next series of diffs, subscriber will also provide reference to the DebuggingOverlay, on which DebuggingRegistry can call all necessary methods to highlight elements. Reviewed By: rshest Differential Revision: D51536787
- Loading branch information
1 parent
8ef807b
commit baaf823
Showing
5 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
packages/react-native/Libraries/Debugging/DebuggingRegistry.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,37 @@ | ||
/** | ||
* 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 | ||
* @oncall react_native | ||
*/ | ||
|
||
import type {AppContainerRootViewRef} from '../ReactNative/AppContainer-dev'; | ||
|
||
export type DebuggingRegistrySubscriberProtocol = { | ||
rootViewRef: AppContainerRootViewRef, | ||
}; | ||
|
||
class DebuggingRegistry { | ||
#registry: Set<DebuggingRegistrySubscriberProtocol> = new Set(); | ||
|
||
subscribe(subscriber: DebuggingRegistrySubscriberProtocol) { | ||
this.#registry.add(subscriber); | ||
} | ||
|
||
unsubscribe(subscriber: DebuggingRegistrySubscriberProtocol) { | ||
const wasPresent = this.#registry.delete(subscriber); | ||
if (!wasPresent) { | ||
console.error( | ||
'[DebuggingRegistry] Unexpected argument for unsubscription, which was not previously subscribed:', | ||
subscriber, | ||
); | ||
} | ||
} | ||
} | ||
|
||
const debuggingRegistryInstance: DebuggingRegistry = new DebuggingRegistry(); | ||
export default debuggingRegistryInstance; |
28 changes: 28 additions & 0 deletions
28
packages/react-native/Libraries/Debugging/useSubscribeToDebuggingRegistry.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,28 @@ | ||
/** | ||
* 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 | ||
* @oncall react_native | ||
*/ | ||
|
||
import type {AppContainerRootViewRef} from '../ReactNative/AppContainer-dev'; | ||
|
||
import DebuggingRegistry from './DebuggingRegistry'; | ||
import {useEffect} from 'react'; | ||
|
||
const useSubscribeToDebuggingRegistry = ( | ||
rootViewRef: AppContainerRootViewRef, | ||
) => { | ||
useEffect(() => { | ||
const subscriber = {rootViewRef}; | ||
|
||
DebuggingRegistry.subscribe(subscriber); | ||
return () => DebuggingRegistry.unsubscribe(subscriber); | ||
}, [rootViewRef]); | ||
}; | ||
|
||
export default useSubscribeToDebuggingRegistry; |
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
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