-
Notifications
You must be signed in to change notification settings - Fork 9
Conversation
- 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
src/formatter.ts
Outdated
}; | ||
|
||
type FileSizeUnits = "b" | "Kb" | "Mb"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum #Closed
src/panels/navigation-timing.ts
Outdated
@@ -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: "⏱️", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
src/panels/resource-timing.ts
Outdated
* 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): {} }>; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/panels/resource-timing.ts
Outdated
* Gets a summary table with default zeroed values. | ||
*/ | ||
export const getZeroedSummaryTable: () => SummaryRow[] = (): SummaryRow[] => { | ||
const zeroValues: SummaryRow = { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
src/panels/resource-timing.ts
Outdated
performance: window.performance, | ||
}; | ||
|
||
export enum INITIATOR_TYPES { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? #Closed
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
#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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
src/panels/resource-timing.ts
Outdated
// Add to the All count | ||
this.incrementCount(summaryCounts[INITIATOR_TYPES.all], entry); | ||
|
||
const index: number = INITIATOR_TYPES[entry.initiatorType as keyof typeof INITIATOR_TYPES]; |
There was a problem hiding this comment.
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
test/button.spec.ts
Outdated
button.render(container); | ||
|
||
if (container.firstElementChild === null) { | ||
throw new Error("Not in DOM"); |
There was a problem hiding this comment.
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:
- Make a common helper function in this PR with a more helpful message
- File a task to make it a Chai assertion or use a standard Chai library
- 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) => { |
There was a problem hiding this comment.
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`; |
There was a problem hiding this comment.
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
src/panels/resource-timing.ts
Outdated
|
||
const numberOfSummaries: number = 8; | ||
const summaryCounts: SummaryRow[] = new Array(numberOfSummaries); | ||
summaryCounts[InitiatorTypes.all] = { ...zeroValues, format: "All" }; |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.