Skip to content

Report v2: port over cards formatter#1992

Merged
brendankenny merged 7 commits intomasterfrom
cards
Apr 14, 2017
Merged

Report v2: port over cards formatter#1992
brendankenny merged 7 commits intomasterfrom
cards

Conversation

@ebidel
Copy link
Copy Markdown
Contributor

@ebidel ebidel commented Apr 11, 2017

R: all

screen shot 2017-04-10 at 10 10 26 pm

This should wait until #1979 and #1987 land and will probably need rebasing, but review can start now. The changes are standalone from those.

* @param {!DetailsJSON} list
* @return {!Element}
*/
_renderCards(list) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not a list :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

_renderCards(list) {
const element = this._dom.createElement('details', 'lighthouse-details');
if (list.header) {
element.appendChild(this._dom.createElement('summary')).textContent = list.header.text;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why are we keeping the verbose header: {type: 'text', text: 'View details'} format if we don't do anything with it (here or in the list formatter)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You mean just use a string: header: 'View details'?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You mean just use a string: header: 'View details'?

or whatever. I'm just wondering why it's a full DetailsJSON if we don't use it

element.appendChild(this._dom.createElement('summary')).textContent = list.header.text;
}

const items = this._dom.createElement('div', 'lighthouse-scorecards');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: need to differentiate types of things here. maybe call this parentElement or something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

}

/**
* @param {!DetailsJSON} list
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this isn't a DetailsJSON, though (specifically list.items isn't a Array<DetailsJSON>|undefined). Maybe you want to create a new CardsDetailsJSON or whatever? I'm also not clear where this leaves us on the whole "new details property has a standard structure" thing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

}
Object.keys(attrs).forEach(key => {
element.setAttribute(key, attrs[key]);
if (attrs[key] !== undefined) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

need to update the attrs type signature if adding this, but it would probably be better to keep it strict and make the caller correct it if they don't want an attribute

Copy link
Copy Markdown
Contributor Author

@ebidel ebidel Apr 13, 2017

Choose a reason for hiding this comment

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

{!Object<?string, ?string>=}?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if it shows up in Object.keys() but is undefined then it would be {!Object<string, (string|undefined)>=} but it's still silly to be passing in undefined attributes. If it's just in that one spot, why not make a const attributes = item.snippet ? {title: item.snippet} : undefined or whatever there

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Every caller will have to do that. I'd rather just prevent attr="undefined" in one place. Kinda what templating languages do for you ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Every caller will have to do that. I'd rather just prevent attr="undefined" in one place. Kinda what templating languages do for you ;)

I'd imagine most templating languages would give you title="undefined" in this case (which I assume is why the current partial has {{#if snippet}}title="{{snippet}}"{{/if}} in it). I'd generally consider accidentally passing in attributes with undefined values a bug and it would be nice to catch that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Exactly. It's replacing that conditional. The good templating systems do this : http://jsbin.com/damayuhiwa/edit?html,output.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess. You should document that behavior in that case so no one is surprised by it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

}

/**
* @param {!CardsDetailsJSON} details
Copy link
Copy Markdown
Contributor

@brendankenny brendankenny Apr 13, 2017

Choose a reason for hiding this comment

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

render() needs to take a {(!DetailsRenderer.DetailsJSON|!DetailsRenderer.CardsDetailsJSON)} now...this is why we need to turn type checking back on :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done. closure is the worst.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

closure is the worst but not for this reason. The parameter can be one of two different things, so... :P


/**
* @param {!DetailsJSON} details
* @param (!DetailsRenderer.DetailsJSON|!DetailsRenderer.CardsDetailsJSON)} details
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

missing a {

}

/**
* @param {!CardsDetailsJSON} details
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

closure is the worst but not for this reason. The parameter can be one of two different things, so... :P

}
Object.keys(attrs).forEach(key => {
element.setAttribute(key, attrs[key]);
if (attrs[key] !== undefined) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Every caller will have to do that. I'd rather just prevent attr="undefined" in one place. Kinda what templating languages do for you ;)

I'd imagine most templating languages would give you title="undefined" in this case (which I assume is why the current partial has {{#if snippet}}title="{{snippet}}"{{/if}} in it). I'd generally consider accidentally passing in attributes with undefined values a bug and it would be nice to catch that

@brendankenny
Copy link
Copy Markdown
Contributor

need a rebase now

@ebidel
Copy link
Copy Markdown
Contributor Author

ebidel commented Apr 14, 2017

rebasing all my life.

#K-Ci & JoJo

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

@brendankenny brendankenny merged commit bd60d6d into master Apr 14, 2017
@brendankenny brendankenny deleted the cards branch April 14, 2017 18:27
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.

2 participants