-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjust report-renderer init for devtools #2002
Conversation
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.
Globals weren't being provided automatically
are these loading in devtools as separate files? It's weird that they can't find each other
*/ | ||
constructor(document) { | ||
this._dom = new DOM(document); | ||
constructor(document, DOM, DetailsRenderer) { |
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.
did you mean to delete this._dom
construction?
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.
thx. restored.
*/ | ||
constructor(document) { | ||
this._dom = new DOM(document); | ||
constructor(document, DOM, DetailsRenderer) { |
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.
also, should they be passed the constructor or an instance?
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.
probably need to update the tests too
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.
also, should they be passed the constructor or an instance
yeah, I'm in favor of passing in already-constructed instances
@@ -87,4 +95,6 @@ class DOM { | |||
|
|||
if (typeof module !== 'undefined' && module.exports) { | |||
module.exports = DOM; | |||
} else if (self) { |
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.
typeof self !== 'undefined'
for all of these? I'm ambivalent between that and just having else { }
since I can't come up with a case where module and self are both undefined :)
ptal! |
@@ -56,11 +56,12 @@ function formatNumber(number) { | |||
|
|||
class ReportRenderer { | |||
/** | |||
* @param {!Document} document | |||
* @param {!DOM} DOM | |||
* @param {!DetailsRenderer} DetailsRenderer |
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.
lowercase the var names
@@ -30,8 +30,11 @@ | |||
<script>%%LIGHTHOUSE_JAVASCRIPT%%</script> | |||
<script>window.__LIGHTHOUSE_JSON__ = %%LIGHTHOUSE_JSON%%;</script> | |||
<script> | |||
const renderer = new ReportRenderer(document); | |||
document.body.appendChild(renderer.renderReport(window.__LIGHTHOUSE_JSON__)); | |||
const dom = new DOM(document); |
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.
Ha, DI! I feel like we'll have to move more implementation out as time goes on. I guess it's fine for now.
@@ -48,7 +49,7 @@ class DOM { | |||
* @throws {Error} | |||
*/ | |||
cloneTemplate(selector) { |
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.
For #2000, I think this should be:
cloneTemplate(selector, context = this.templatesContext) {
const template = context.querySelector(selector);
...
}
so we can override where to look for subtemplates.
okay @brendankenny @ebidel. all ready for ya? |
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.
LGTM. Just some nits
* helpText: string, | ||
* score: (number|boolean), | ||
* scoringMode: string, | ||
* details: (DetailsRenderer.DetailsJSON|DetailsRenderer.CardsDetailsJSON|undefined) |
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.
(!DetailsRenderer.DetailsJSON|!DetailsRenderer.CardsDetailsJSON|undefined)
I think
* weight: number, | ||
* score: number, | ||
* description: string, | ||
* audits: Array<ReportRenderer.AuditJSON> |
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.
!Array<!ReportRenderer.AuditJSON>
} | ||
|
||
/** | ||
* @param {!Document|!Element} context |
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.
maybe a function description for why you'd want to inject this? there won't be any hints on the LH side
@@ -33,7 +33,8 @@ class DOM { | |||
* set the attribute on the node. | |||
* @return {!Element} | |||
*/ | |||
createElement(name, className, attrs = {}) { | |||
createElement(name, className, attrs) { | |||
attrs = attrs || {}; |
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.
TODO switch this back when https://codereview.chromium.org/2821773002/ lands?
* @typedef {{ | ||
* type: string, | ||
* text: (string|undefined), | ||
* header: (DetailsRenderer.DetailsJSON|undefined), |
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.
(!DetailsRenderer.DetailsJSON|undefined)
/** @typedef {{ | ||
* type: string, | ||
* text: string, | ||
* header: DetailsJSON, |
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.
!DetailsJSON
* type: string, | ||
* text: string, | ||
* header: DetailsJSON, | ||
* items: Array<{title: string, value: string, snippet: string|undefined, target: 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.
!Array
. did it need parens around snippet's type?
Gettin the new report going in DevTools and wanted some changes like these.
e.g. my subclass currently looks like (UPDATED):
Screenshot btw: