Bug 1630660 - Memoize Callstack FrameLocation component. r=davidwalsh

Differential Revision: https://phabricator.services.mozilla.com/D71196
This commit is contained in:
Jason Laster 2020-04-20 18:39:28 +00:00
Родитель d44543d089
Коммит 09c1383143
2 изменённых файлов: 29 добавлений и 24 удалений

Просмотреть файл

@ -3,7 +3,7 @@
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// @flow // @flow
import React, { Component } from "react"; import React, { Component, memo } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import classNames from "classnames"; import classNames from "classnames";
@ -30,34 +30,36 @@ function FrameTitle({ frame, options = {}, l10n }: FrameTitleProps) {
type FrameLocationProps = { frame: Frame, displayFullUrl: boolean }; type FrameLocationProps = { frame: Frame, displayFullUrl: boolean };
function FrameLocation({ frame, displayFullUrl = false }: FrameLocationProps) { const FrameLocation = memo(
if (!frame.source) { ({ frame, displayFullUrl = false }: FrameLocationProps) => {
return null; if (!frame.source) {
} return null;
}
if (frame.library) {
return (
<span className="location">
{frame.library}
<AccessibleImage
className={`annotation-logo ${frame.library.toLowerCase()}`}
/>
</span>
);
}
const { location, source } = frame;
const filename = displayFullUrl
? getFileURL(source, false)
: getFilename(source);
if (frame.library) {
return ( return (
<span className="location"> <span className="location" title={source.url}>
{frame.library} <span className="filename">{filename}</span>:
<AccessibleImage <span className="line">{location.line}</span>
className={`annotation-logo ${frame.library.toLowerCase()}`}
/>
</span> </span>
); );
} }
);
const { location, source } = frame;
const filename = displayFullUrl
? getFileURL(source, false)
: getFilename(source);
return (
<span className="location" title={source.url}>
<span className="filename">{filename}</span>:
<span className="line">{location.line}</span>
</span>
);
}
FrameLocation.displayName = "FrameLocation"; FrameLocation.displayName = "FrameLocation";

Просмотреть файл

@ -78,6 +78,8 @@ function getDocumentForUrl(dbg, url) {
return getDocument(source.id); return getDocument(source.id);
} }
const diff = (a, b) => Object.keys(a).filter(key => !Object.is(a[key], b[key]));
export function setupHelper(obj: Object) { export function setupHelper(obj: Object) {
const selectors = bindSelectors(obj); const selectors = bindSelectors(obj);
const dbg: Object = { const dbg: Object = {
@ -105,6 +107,7 @@ export function setupHelper(obj: Object) {
_telemetry: { _telemetry: {
events: {}, events: {},
}, },
diff,
}; };
window.dbg = dbg; window.dbg = dbg;