update per review comments

This commit is contained in:
Mengdi Chen
2022-03-29 13:07:01 -04:00
parent 60cb32bf93
commit 12ecbea744
3 changed files with 7 additions and 34 deletions
@@ -1,27 +0,0 @@
/**
* 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
*/
/**
* This file contains a list of custom Errors that ReactDebugTools can throw in
* special occasions.
* The names of the errors are exported so that other packages (such as DevTools)
* can use them to detect and handle them separately.
*/
export const ErrorsNames = {
UNSUPPORTTED_FEATURE_ERROR: 'UnsupportedFeatureError',
};
// For now we just override the name. If we decide to move react-debug-tools to
// devtools package, we should use a real Error class instead.
export function createUnsupportedFeatureError(message: string = '') {
const error = new Error(message);
error.name = ErrorsNames.UNSUPPORTTED_FEATURE_ERROR;
return error;
}
+6 -5
View File
@@ -29,7 +29,6 @@ import {
ContextProvider,
ForwardRef,
} from 'react-reconciler/src/ReactWorkTags';
import {createUnsupportedFeatureError} from './ReactDebugCustomErrors';
type CurrentDispatcherRef = typeof ReactSharedInternals.ReactCurrentDispatcher;
@@ -362,11 +361,13 @@ const Dispatcher: DispatcherType = {
const DispatcherProxyHandler = {
get(target, prop, _receiver) {
if (target.hasOwnProperty(prop)) {
return Reflect.get(...arguments);
return target[prop];
}
throw createUnsupportedFeatureError(
'Missing method in Dispatcher: ' + prop,
);
const error = new Error('Missing method in Dispatcher: ' + prop);
// Note: This error name needs to stay in sync with react-devtools-shared
// TODO: refactor this if we ever combine the devtools and debug tools packages
error.name = 'UnsupportedFeatureError';
throw error;
},
};
+1 -2
View File
@@ -8,6 +8,5 @@
*/
import {inspectHooks, inspectHooksOfFiber} from './ReactDebugHooks';
import {ErrorsNames} from './ReactDebugCustomErrors';
export {inspectHooks, inspectHooksOfFiber, ErrorsNames};
export {inspectHooks, inspectHooksOfFiber};