/
githubmr
/
facebook-react
Обзор
Документация
Войти
/
githubmr
/
facebook-react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
v18.0.0
packages/react-devtools-shared/src/Logger.js
61 строка
2 KB
jstejada
[DevTools] Log errors occurring or reported to the frontend (#22948)
13 дек 2021, 19:38
Не верифицирован
13 дек 2021, 19:38
a049aa0
Код
Авторство
О чём код?
/** * 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'; export type LogEvent = | {| +event_name: 'loaded-dev-tools', |} | {| +event_name: 'error', +error_message: string | null, +error_stack: string | null, +error_component_stack: string | null, |} | {| +event_name: 'selected-components-tab', |} | {| +event_name: 'selected-profiler-tab', |} | {| +event_name: 'load-hook-names', +event_status: 'success' | 'error' | 'timeout' | 'unknown', +duration_ms: number, +inspected_element_display_name: string | null, +inspected_element_number_of_hooks: number | null, |}; export type LogFunction = LogEvent => void; let logFunctions: Array<LogFunction> = []; export const logEvent: LogFunction = enableLogger === true ? function logEvent(event: LogEvent): void { logFunctions.forEach(log => { log(event); }); } : function logEvent() {}; export const registerEventLogger = enableLogger === true ? function registerEventLogger(logFunction: LogFunction): () => void { if (enableLogger) { logFunctions.push(logFunction); return function unregisterEventLogger() { logFunctions = logFunctions.filter(log => log !== logFunction); }; } return () => {}; } : function registerEventLogger(logFunction: LogFunction) { return () => {}; };