Skip to content
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

Merged
merged 8 commits into from
Apr 14, 2017
Merged

Adjust report-renderer init for devtools #2002

merged 8 commits into from
Apr 14, 2017

Conversation

paulirish
Copy link
Member

@paulirish paulirish commented Apr 13, 2017

Gettin the new report going in DevTools and wanted some changes like these.

  1. Since I'm subclassing, I need to pass in those subclasses.
  2. Globals weren't being provided automatically. (I think because devtools uses eval?)

e.g. my subclass currently looks like (UPDATED):
image

Screenshot btw:
image

Copy link
Member

@brendankenny brendankenny left a 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) {
Copy link
Member

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?

Copy link
Member Author

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) {
Copy link
Collaborator

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?

Copy link
Collaborator

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

Copy link
Member

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) {
Copy link
Collaborator

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 :)

@paulirish
Copy link
Member Author

ptal!

@@ -56,11 +56,12 @@ function formatNumber(number) {

class ReportRenderer {
/**
* @param {!Document} document
* @param {!DOM} DOM
* @param {!DetailsRenderer} DetailsRenderer
Copy link
Contributor

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);
Copy link
Contributor

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.

ebidel
ebidel previously requested changes Apr 14, 2017
@@ -48,7 +49,7 @@ class DOM {
* @throws {Error}
*/
cloneTemplate(selector) {
Copy link
Contributor

@ebidel ebidel Apr 14, 2017

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.

@paulirish
Copy link
Member Author

okay @brendankenny @ebidel. all ready for ya?

Copy link
Member

@brendankenny brendankenny left a 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)
Copy link
Member

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>
Copy link
Member

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
Copy link
Member

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 || {};
Copy link
Member

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),
Copy link
Member

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,
Copy link
Member

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}>
Copy link
Member

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?

@paulirish paulirish merged commit b12f2ea into master Apr 14, 2017
@paulirish paulirish deleted the rendererinit branch April 14, 2017 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants