From a0b35665a19f40bde51153eb06021accd657200d Mon Sep 17 00:00:00 2001 From: Tharaka Wijebandara Date: Wed, 4 Oct 2017 23:16:10 +0530 Subject: [PATCH] Rename `openInEditor` to `editorHandler` - Remove indirection of openInEditorListener - Check editorHandler for null before styling error clickable --- packages/react-dev-utils/webpackHotDevClient.js | 2 +- .../src/containers/CompileErrorContainer.js | 9 +++++---- .../src/containers/RuntimeError.js | 6 +++--- .../src/containers/RuntimeErrorContainer.js | 4 ++-- .../src/containers/StackFrame.js | 15 ++++++++------- .../src/containers/StackTrace.js | 6 +++--- .../react-error-overlay/src/iframeScript.js | 6 +++--- packages/react-error-overlay/src/index.js | 17 +++++++---------- 8 files changed, 32 insertions(+), 33 deletions(-) diff --git a/packages/react-dev-utils/webpackHotDevClient.js b/packages/react-dev-utils/webpackHotDevClient.js index 888482dde44..e375c3fab8d 100644 --- a/packages/react-dev-utils/webpackHotDevClient.js +++ b/packages/react-dev-utils/webpackHotDevClient.js @@ -23,7 +23,7 @@ var launchEditorEndpoint = require('./launchEditorEndpoint'); var formatWebpackMessages = require('./formatWebpackMessages'); var ErrorOverlay = require('react-error-overlay'); -ErrorOverlay.listenToOpenInEditor(function OpenInEditor(errorLocation) { +ErrorOverlay.setEditorHandler(function editorHandler(errorLocation) { // Keep this sync with errorOverlayMiddleware.js fetch( `${launchEditorEndpoint}?fileName=` + diff --git a/packages/react-error-overlay/src/containers/CompileErrorContainer.js b/packages/react-error-overlay/src/containers/CompileErrorContainer.js index 85528142a64..7f689efac2e 100644 --- a/packages/react-error-overlay/src/containers/CompileErrorContainer.js +++ b/packages/react-error-overlay/src/containers/CompileErrorContainer.js @@ -21,19 +21,20 @@ const codeAnchorStyle = { type Props = {| error: string, - openInEditor: (errorLoc: ErrorLocation) => void, + editorHandler: (errorLoc: ErrorLocation) => void, |}; class CompileErrorContainer extends PureComponent { render() { - const { error, openInEditor } = this.props; + const { error, editorHandler } = this.props; const errLoc: ?ErrorLocation = parseCompileError(error); + const canOpenInEditor = errLoc !== null && editorHandler !== null; return (
openInEditor(errLoc) : null} - style={errLoc ? codeAnchorStyle : null} + onClick={canOpenInEditor ? () => editorHandler(errLoc) : null} + style={canOpenInEditor ? codeAnchorStyle : null} > diff --git a/packages/react-error-overlay/src/containers/RuntimeError.js b/packages/react-error-overlay/src/containers/RuntimeError.js index 534d777494d..1db2aba79b9 100644 --- a/packages/react-error-overlay/src/containers/RuntimeError.js +++ b/packages/react-error-overlay/src/containers/RuntimeError.js @@ -27,10 +27,10 @@ export type ErrorRecord = {| type Props = {| errorRecord: ErrorRecord, - openInEditor: (errorLoc: ErrorLocation) => void, + editorHandler: (errorLoc: ErrorLocation) => void, |}; -function RuntimeError({ errorRecord, openInEditor }: Props) { +function RuntimeError({ errorRecord, editorHandler }: Props) { const { error, unhandledRejection, contextSize, stackFrames } = errorRecord; const errorName = unhandledRejection ? 'Unhandled Rejection (' + error.name + ')' @@ -59,7 +59,7 @@ function RuntimeError({ errorRecord, openInEditor }: Props) { stackFrames={stackFrames} errorName={errorName} contextSize={contextSize} - openInEditor={openInEditor} + editorHandler={editorHandler} /> ); diff --git a/packages/react-error-overlay/src/containers/RuntimeErrorContainer.js b/packages/react-error-overlay/src/containers/RuntimeErrorContainer.js index 9905b6de48e..91d4a4f5456 100644 --- a/packages/react-error-overlay/src/containers/RuntimeErrorContainer.js +++ b/packages/react-error-overlay/src/containers/RuntimeErrorContainer.js @@ -19,7 +19,7 @@ import type { ErrorLocation } from '../utils/parseCompileError'; type Props = {| errorRecords: ErrorRecord[], close: () => void, - openInEditor: (errorLoc: ErrorLocation) => void, + editorHandler: (errorLoc: ErrorLocation) => void, |}; type State = {| @@ -75,7 +75,7 @@ class RuntimeErrorContainer extends PureComponent { )}