Skip to content

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
Contributor

@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
Contributor

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
Contributor

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

if (typeof module !== 'undefined' && module.exports) {
module.exports = DOM;
} else if (self) {
self.DOM = DOM;
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!

/**
* @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

<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
* @return {!DocumentFragment} A clone of the template content.
* @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
Contributor

@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
Contributor

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
Contributor

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
Contributor

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

*/
createElement(name, className, attrs = {}) {
createElement(name, className, attrs) {
attrs = attrs || {};
Copy link
Contributor

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
Contributor

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
Contributor

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
Contributor

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