angular / angular/components

feature request: Simplify MatTree setup

Aperta
#11,446 2 commenti 7 reazioni 0 assegnatari Vedi su GitHub
area: material/tree feature P3
Lingua principale
TypeScript
Stelle
25k
Fork
6.8k
Merge medio
1g 8h
PR unite (30g)
91

Descrizione

#### 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?

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con la demo ufficiale tree-checklist e il relativo punto di ingresso app/tree-checklist-example.ts, quindi esamina la configurazione di MatTreeFlattener, FlatTreeControl e MatTreeFlatDataSource descritta nell’issue. Il lavoro è completato quando viene concordata e implementata un’API di origine dati MatTree più semplice che rimuova i callback ripetuti preservando il comportamento dell’albero mostrato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
angular, typescript
Ambito
frontend
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.