-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DevTools] Add initial APIs for logging instrumentation events under …
…feature flag (#22276)
- Loading branch information
Juan
authored
Sep 14, 2021
1 parent
263cfa6
commit 50263d3
Showing
13 changed files
with
234 additions
and
110 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its 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 | ||
*/ | ||
|
||
import {enableLogger} from 'react-devtools-feature-flags'; | ||
|
||
type LoadHookNamesEvent = {| | ||
+name: 'loadHookNames', | ||
+displayName: string | null, | ||
+numberOfHooks: number | null, | ||
+durationMs: number, | ||
+resolution: 'success' | 'error' | 'timeout' | 'unknown', | ||
|}; | ||
|
||
// prettier-ignore | ||
export type LogEvent = | ||
| LoadHookNamesEvent; | ||
|
||
export type LogFunction = LogEvent => void; | ||
|
||
let loggers: Array<LogFunction> = []; | ||
export const logEvent: LogFunction = | ||
enableLogger === true | ||
? function logEvent(event: LogEvent): void { | ||
loggers.forEach(log => { | ||
log(event); | ||
}); | ||
} | ||
: function logEvent() {}; | ||
|
||
export const registerEventLogger = | ||
enableLogger === true | ||
? function registerEventLogger(eventLogger: LogFunction): () => void { | ||
if (enableLogger) { | ||
loggers.push(eventLogger); | ||
return function unregisterEventLogger() { | ||
loggers = loggers.filter(logger => logger !== eventLogger); | ||
}; | ||
} | ||
return () => {}; | ||
} | ||
: function registerEventLogger() {}; |
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
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
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
Oops, something went wrong.