mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
DebuggerSessionObserver: JavaScript API (#46043)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46043 # Changelog: [Internal] Defined JavaScript interface, which can be used by other modules, such as LogBox, which will be migrated in the next diff Reviewed By: robhogan Differential Revision: D61301333 fbshipit-source-id: 63bb8581b893d0fdcb36e1fa16d243f1a5b08ac4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
dd26c3c1d4
commit
2e545b10f5
@@ -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
|
||||
* @format
|
||||
* @oncall react_native
|
||||
*/
|
||||
|
||||
class FuseboxSessionObserver {
|
||||
#hasNativeSupport: boolean;
|
||||
|
||||
constructor() {
|
||||
this.#hasNativeSupport = global.hasOwnProperty(
|
||||
'__DEBUGGER_SESSION_OBSERVER__',
|
||||
);
|
||||
}
|
||||
|
||||
hasActiveSession(): boolean {
|
||||
if (!this.#hasNativeSupport) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return global.__DEBUGGER_SESSION_OBSERVER__.hasActiveSession;
|
||||
}
|
||||
|
||||
subscribe(callback: (status: boolean) => void): () => void {
|
||||
if (!this.#hasNativeSupport) {
|
||||
return () => {};
|
||||
}
|
||||
|
||||
global.__DEBUGGER_SESSION_OBSERVER__.subscribers.add(callback);
|
||||
return () => {
|
||||
global.__DEBUGGER_SESSION_OBSERVER__.subscribers.delete(callback);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const observerInstance: FuseboxSessionObserver = new FuseboxSessionObserver();
|
||||
export default observerInstance;
|
||||
Reference in New Issue
Block a user