Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Add the resource timings pane #5

Merged
merged 23 commits into from
Jan 17, 2018
Merged

Add the resource timings pane #5

merged 23 commits into from
Jan 17, 2018

Conversation

AdamTReineke
Copy link
Contributor

Adds the resource timings pane which provides a two tables: a summary table and a list of files.

Additionally updates project config files as needed and modifies helpers to be cleaner. See individual commit descriptions for more details, especially dd6c766.

Adam Reineke added 14 commits January 4, 2018 19:07
- Added more `npm run ...` commands
- No more sourcemaps
- Update tslint to allow leading underscores in variable names (for unused variables in the mocks)
- Remove the unused webpack test config
- Rename the units type in Formatter
- Fix a minor typing issue in IPanel
- Move and update helpers in resource-timing
- Add a tsconfig for the tests project so it can be typechecked properly
- Fix tslint and tsc type errors in `button.spec.ts`, `formatter.spec.ts`, `toolbar.spec.ts`, `panel.mock.ts`, `navigation-timing-spec.ts`
- Add resource timing tests
@AdamTReineke
Copy link
Contributor Author

AdamTReineke commented Jan 12, 2018

Screenshot of the pane injected into GitHub:
image
#ByDesign

src/formatter.ts Outdated
};

type FileSizeUnits = "b" | "Kb" | "Mb";

Copy link
Contributor

@Dadstart Dadstart Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum #Closed

@@ -42,6 +42,7 @@ export class NavigationTimingsPanel implements IPanel {
public getButtons(): Button[] {
return [new Button({
parent: this,
title: "Duration from navigation to end of load event",
emoji: "⏱️",
Copy link
Contributor

@Dadstart Dadstart Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we're not localizing these strings, but I'm a huge fan of having any UI strings being defined in a separate file. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really want the panels to be as independent as possible. However, I'll move the strings into the default config (around line 15) so they're in one place and could be injected by someone else if they wanted to localize their implementation.


In reply to: 161262870 [](ancestors = 161262870)

* The global performance object, can be included in the config to enable injection of a mock object for testing.
* This pane only requires the getEntriesByType method
*/
performance: Partial<Performance> & Required<{ getEntriesByType(entryType: string): {} }>;
Copy link
Contributor

@Dadstart Dadstart Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

& [](start = 38, length = 1)

I haven't seen this syntax before #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See Intersection Types here


In reply to: 161263142 [](ancestors = 161263142)

* Gets a summary table with default zeroed values.
*/
export const getZeroedSummaryTable: () => SummaryRow[] = (): SummaryRow[] => {
const zeroValues: SummaryRow = {
Copy link
Contributor

@Dadstart Dadstart Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing the () => = () => pattern all over. What is this doing as opposed to just () =>? #Closed

Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually -1 on declaring types on lambdas (which is what this is). It's redundant, and makes it likely to mismatch types eventually (two sources of truth). #Resolved

performance: window.performance,
};

export enum INITIATOR_TYPES {
Copy link
Contributor

@Dadstart Dadstart Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INITIATOR_TYPES [](start = 12, length = 15)

Is it common practice to have enums be all caps? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. The values normally are uppercased, but can't be in this case since the names have other meanings. (Which I'll add a comment to note.)


In reply to: 161263665 [](ancestors = 161263665)

@@ -4,7 +4,7 @@
"noImplicitAny": true,
"module": "es2015",
"target": "es5",
"sourceMap": true,
"sourceMap": false,
"listFiles": true,
Copy link
Contributor

@Dadstart Dadstart Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed since it wasn't particularly helpful. Can be added back in later if people need it.


In reply to: 161264406 [](ancestors = 161264406)

tslint.json Outdated
@@ -26,7 +26,8 @@
"no-implicit-dependencies": [true, "dev"],
"no-import-side-effect": false,
"strict-boolean-expressions": [true, "allow-undefined-union"],
"interface-over-type-literal": false
"interface-over-type-literal": false,
"variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore"]
Copy link
Contributor

@Dadstart Dadstart Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"allow-leading-underscore" [](start = 64, length = 26)

Why allow leading underscore #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See MockPanel (panel.mock.ts) which needs to implement the constructor and render functions. I don't need the values from required parameters so TSC flags on unused variables. Unused parameters with leading underscores are exempt from this check though. See more at microsoft/TypeScript#9458


In reply to: 161264493 [](ancestors = 161264493)

Copy link
Contributor

@Dadstart Dadstart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

!injectDemoToolbar.user.js
!commontypes.d.ts
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of your source, so it shouldn't be gitignored. #ByDesign

Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(if you're doing something fancy about not changing the API, document it) #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hence the ! in front. :-)


In reply to: 161152364 [](ancestors = 161152364)

}
#PTB_buttons li {
display:inline-block;
line-height:1.6em;
margin-left:0.5em;
padding:0.2em;
cursor:pointer;

border:1px solid black;
border-bottom: none;
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: some styles have a space after the colon; some don't. #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't fix because this is getting moved to JavaScript soon. I'll standardize then.


In reply to: 161152446 [](ancestors = 161152446)

src/formatter.ts Outdated
case "Mb":
return `${(bytes / (twoExpTen * twoExpTen)).toLocaleString(undefined, LOCALE_STRING_DECIMAL_PLACES)} Mb`;
default:
throw new Error("unknown unit");
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like you should turn off the TSLint rule or find/make a config that allows for exhaustive switches. This code should never be hit, and is just wasted bytes. #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By Design, since the value can be passed in from JS code that wouldn't know the type limitations.


In reply to: 161152748 [](ancestors = 161152748)

// Add to the All count
this.incrementCount(summaryCounts[INITIATOR_TYPES.all], entry);

const index: number = INITIATOR_TYPES[entry.initiatorType as keyof typeof INITIATOR_TYPES];
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type here should be number | undefined; then you wouldn't have to cast a line down. #Closed

button.render(container);

if (container.firstElementChild === null) {
throw new Error("Not in DOM");
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message isn't particularly useful and is repeated in a few places. Suggest you:

  1. Make a common helper function in this PR with a more helpful message
  2. File a task to make it a Chai assertion or use a standard Chai library
  3. Merge this PR #Resolved

src/formatter.ts Outdated
@@ -9,10 +12,71 @@ export const DECIMAL_PLACES: number = 2;
* @param decimalPlaces The number of decimal places to show.
*/
export const duration: (end: number, start: number, decimalPlaces?: number) => string =
(end: number, start: number, decimalPlaces: number = DECIMAL_PLACES): string => {
if (isNaN(end) || isNaN(start)) {
(end, start, decimalPlaces = DECIMAL_PLACES) => {
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg Jan 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in person: it's driving me crazy that you have duplicate type declarations here (one explicit, one implicit).

Instead of:

export const duration: (end: number, start: number, decimalPlaces?: number) => string =
     (end, start, decimalPlaces = DECIMAL_PLACES) => { /* ... */ };

...it would be simpler to write:

export const duration = (end: number, start: number, decimalPlaces?: number): string => { /* ... */ };
``` #Resolved

src/formatter.ts Outdated

switch (unit) {
case "b":
return `${bytes.toLocaleString(undefined, LOCALE_STRING_DECIMAL_PLACES)} b`;
Copy link
Contributor

@Dadstart Dadstart Jan 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case FileSizeUnits[FileSizeUnits.b]
rather than duplicating the string val #Closed


const numberOfSummaries: number = 8;
const summaryCounts: SummaryRow[] = new Array(numberOfSummaries);
summaryCounts[InitiatorTypes.all] = { ...zeroValues, format: "All" };
Copy link
Contributor

@Dadstart Dadstart Jan 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"All" [](start = 64, length = 6)

InitiatorTypes[InitiatorTypes.all] #Closed

<tr>
<td>${entry.initiatorType}</td>
<td title="${entry.name}">${Formatter.pathToFilename(entry.name)}</td>
<td class="numeric">${Formatter.sizeToString(entry.transferSize)}</td>
Copy link
Contributor

@Dadstart Dadstart Jan 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numeric [](start = 15, length = 7)

Are you sure this will be matched as PTB_frame.numeric over a separate .numeric class defined by the library consumer included after the PTB CSS? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no complete solution to this since any styles are at the mercy of the page overriding them. (For example, I don't specify a font face anywhere so I get whatever the page gives us.) Shadow DOM is the ideal protector but it's only in Chrome for now.


In reply to: 162096583 [](ancestors = 162096583)

Copy link
Contributor

@Dadstart Dadstart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@AdamTReineke AdamTReineke merged commit acbb974 into master Jan 17, 2018
@AdamTReineke AdamTReineke deleted the resource-timing branch January 17, 2018 21:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants