Skip to content

chore: enforce consistency in material-examples #11539

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

Merged
merged 1 commit into from
Jun 20, 2018
Merged

chore: enforce consistency in material-examples #11539

merged 1 commit into from
Jun 20, 2018

Conversation

rafaelss95
Copy link
Contributor

This:

  • Enables ViewEncapsulation;
  • Ensures that all css classes are initialized with .example-;
  • Ensures all spaces between curly braces are ommitted (in component [objects] and html);
  • Replaces redundant syntax for boolean @Inputs, like: <mat-horizontal-stepper linear="true"> with sugar syntax <mat-horizontal-stepper linear>;
  • Replaces all any usages with more expressive types;
  • Replaces classes with interfaces;
  • Creates interfaces for complex examples (generally arrays);
  • Removes unnecessary type assertions;
  • Indents files correctly (some were indented with 4 spaces);

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label May 27, 2018
node.children = this.buildFileTree(v, level + 1);
} else {
node.type = v;
buildFileTree(obj: object, level: number): FileNode[] {
Copy link
Member

Choose a reason for hiding this comment

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

obj: object is about as useful as value: any. Don't we know the type here?

Copy link
Contributor Author

@rafaelss95 rafaelss95 May 29, 2018

Choose a reason for hiding this comment

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

Unfortunately we don't have the type, because we just parse a "stringified" JSON and it becomes any.

@@ -141,13 +135,10 @@ export class CdkTreeFlatExample {
});
}

hasChild = (_: number, _nodeData: FileFlatNode) => { return _nodeData.expandable; };
Copy link
Member

Choose a reason for hiding this comment

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

Can be reduced further to:

hasChild = (_: number, _nodeData: FileFlatNode) => _nodeData.expandable;

node.children = this.buildFileTree(v, level + 1);
} else {
node.type = v;
buildFileTree(obj: object, level: number): FileNode[] {
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above. We should know the type of the obj here.


hasNestedChild = (_: number, nodeData: FileNode) => {return !(nodeData.type); };
private _getChildren = (node: FileNode) => { return observableOf(node.children); };
Copy link
Member

Choose a reason for hiding this comment

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

These two can be reduced to:

hasNestedChild = (_: number, nodeData: FileNode) => !nodeData.type;
private _getChildren = (node: FileNode) => observableOf(node.children);

Copy link
Member

Choose a reason for hiding this comment

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

This one still hasn't been addressed @rafaelss95.

@@ -18,6 +18,6 @@
<mat-form-field>
<input matInput [matDatepicker]="dp3" placeholder="Input disabled" disabled>
<mat-datepicker-toggle matSuffix [for]="dp3"></mat-datepicker-toggle>
<mat-datepicker #dp3 disabled="false"></mat-datepicker>
<mat-datepicker #dp3 [disabled]="false"></mat-datepicker>
Copy link
Member

Choose a reason for hiding this comment

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

The old usage was also valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, however shouldn't we prefer to pass the literal false instead of string with false value?

Copy link
Member

Choose a reason for hiding this comment

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

Since we handle both strings and booleans, and the value doesn't change, it would be better to use the string binding. See the template syntax docs.

@@ -8,8 +8,8 @@ import {ChangeDetectorRef, Component, NgZone} from '@angular/core';
styleUrls: ['focus-monitor-directives-example.css']
})
export class FocusMonitorDirectivesExample {
elementOrigin: string = this.formatOrigin(null);
subtreeOrigin: string = this.formatOrigin(null);
elementOrigin = this.formatOrigin(null);
Copy link
Member

Choose a reason for hiding this comment

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

Why was the type removed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, formatOrigin returns a string, so elementOrigin is automatically inferred as string, there's no necessity to be redundant.

let flatNode = this.nestedNodeMap.has(node) && this.nestedNodeMap.get(node)!.item === node.item
? this.nestedNodeMap.get(node)!
: new TodoItemFlatNode();
const existentNode = this.nestedNodeMap.get(node);
Copy link
Member

Choose a reason for hiding this comment

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

existentNode -> existingNode

}
if (change.removed) {
change.removed.reverse().forEach((node) => this.toggleNode(node, false));
change.removed.reverse().forEach(node => this.toggleNode(node, false));
Copy link
Member

Choose a reason for hiding this comment

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

Might be a good idea to add a slice() before the reverse here since reverse will reverse the array in place.

@@ -128,10 +123,14 @@ export class TreeLoadmoreExample {
getChildren = (node: LoadmoreNode): Observable<LoadmoreNode[]> => { return node.childrenChange; };

transformer = (node: LoadmoreNode, level: number) => {
if (this.nodeMap.has(node.item)) {
return this.nodeMap.get(node.item)!;
const existentNode = this.nodeMap.get(node.item);
Copy link
Member

Choose a reason for hiding this comment

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

existentNode -> existingNode


hasNestedChild = (_: number, nodeData: FileNode) => {return !(nodeData.type); };
private _getChildren = (node: FileNode) => { return observableOf(node.children); };
Copy link
Member

Choose a reason for hiding this comment

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

Can be reduced to:

hasNestedChild = (_: number, nodeData: FileNode) => !nodeData.type;
private _getChildren = (node: FileNode) => observableOf(node.children);

@rafaelss95
Copy link
Contributor Author

@crisbeto Ready for another review round.

@ngbot
Copy link

ngbot bot commented Jun 7, 2018

Hi @rafaelss95! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@rafaelss95
Copy link
Contributor Author

@crisbeto is there something that I can do to speed up this PR?

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM


hasNestedChild = (_: number, nodeData: FileNode) => {return !(nodeData.type); };
private _getChildren = (node: FileNode) => { return observableOf(node.children); };
Copy link
Member

Choose a reason for hiding this comment

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

This one still hasn't been addressed @rafaelss95.

@crisbeto crisbeto added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Jun 12, 2018
@rafaelss95
Copy link
Contributor Author

Done @crisbeto.

@tinayuangao tinayuangao merged commit f59cf59 into angular:master Jun 20, 2018
@rafaelss95 rafaelss95 deleted the consistent-material-examples branch June 21, 2018 00:50
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants