feature request: Simplify MatTree setup
- 主要言語
- TypeScript
- スター
- 25k
- フォーク
- 6.8k
- 平均マージ
- 1日 8時間
- マージ済み PR(30日)
- 91
説明
#### 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?
コントリビューションガイド
調査の方向性
公式の tree-checklist デモとそのエントリーポイント app/tree-checklist-example.ts から始め、Issue に記載されている MatTreeFlattener、FlatTreeControl、MatTreeFlatDataSource のセットアップを確認します。完了条件は、繰り返される callbacks を削除し、実例で示されているツリーの動作を維持する、よりシンプルな MatTree データソース API について合意し、実装することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- angular, typescript
- 領域
- frontend
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100