feature request: Simplify MatTree setup
- Vorherrschende Sprache
- TypeScript
- Sterne
- 25k
- Forks
- 6.8k
- Ø Merge
- 1 T. 8 Std.
- Gemergte PRs (30 T.)
- 91
Beschreibung
#### Bug, feature request, or proposal:
feature request
#### What is the expected behavior?
To simlify matTree setup
#### What is the current behavior?
we use lots of codes to setup a flatten tree
```javascript
this.treeFlattener = new MatTreeFlattener(this.transformer, this.getLevel,
this.isExpandable, this.getChildren);
this.treeControl = new FlatTreeControl(this.getLevel, this.isExpandable);
this.dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
this.database.dataChange.subscribe(data => {
this.dataSource.data = data;
});
getLevel = (node: TodoItemFlatNode) => node.level;
isExpandable = (node: TodoItemFlatNode) => node.expandable;
getChildren = (node: TodoItemNode): Observable => {
return ofObservable(node.children);
}
hasChild = (_: number, _nodeData: TodoItemFlatNode) => _nodeData.expandable;
hasNoContent = (_: number, _nodeData: TodoItemFlatNode) => _nodeData.item === '';
```
#### What are the steps to reproduce?
[official demo](https://run.stackblitz.com/api/angular/v1?file=app%2Ftree-checklist-example.ts)
#### What is the use-case or motivation for changing an existing behavior?
1. Convention over configuration
We should follow a convention rather than do too many configuration.
All tree datasource has the same property such as `children`, `level`, `expandable`
2. Proposal
```javascript
// to define a material tree interface
export interface MatTreeNode {
level: number;
expandable: boolean,
children: Array
}
// all tree nodes must implements tree data interface
export class MyTreeNode implements MatTreeNode {
// ... business logic
}
// only need to pass Array to setup tree component
this.treeDataSource = new MatTreeDataSource(Array);
```
#### Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular 6.0.0
Material 6.0.0
Typescript 2.7.2
#### Is there anything else we should know?
Beitragsleitfaden
Rechercherichtung
Beginne mit der offiziellen tree-checklist-Demo und ihrem Einstiegspunkt app/tree-checklist-example.ts und überprüfe anschließend das im Issue beschriebene Setup von MatTreeFlattener, FlatTreeControl und MatTreeFlatDataSource. Als abgeschlossen gilt die Einigung auf eine einfachere MatTree-Datenquellen-API und deren Implementierung, die die wiederholten Callbacks entfernt und dabei das gezeigte Baumverhalten beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- angular, typescript
- Bereich
- frontend
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100