Skip to content

Commit 2cfb9aa

Browse files
committed
chore(*): move ng2-tree to Angular v5
1 parent 9626db7 commit 2cfb9aa

File tree

10 files changed

+106
-11580
lines changed

10 files changed

+106
-11580
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ node_modules
1313
*.swp
1414
npm-debug.log
1515
yarn-error.log
16+
package-lock.json

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

README.md

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [tree](#tree)
1313
- [[tree]](#tree)
1414
- [Load children asynchronously](#load-children-asynchronously)
15+
- [Load children using ngrx (or any redux-like library)](#load-children-using-ngrx-or-any-redux-like-library)
1516
- [Configure node via TreeModelSettings](#configure-node-via-treemodelsettings)
1617
- [[settings]](#settings)
1718
- [`Tree` class](#tree-class)
@@ -23,18 +24,20 @@
2324
- [NodeRenamedEvent](#noderenamedevent)
2425
- [NodeExpandedEvent](#nodeexpandedevent)
2526
- [NodeCollapsedEvent](#nodecollapsedevent)
27+
- [LoadNextLevelEvent](#loadnextlevelevent)
2628
- [:gun: Controller](#gun-controller)
27-
- [select - selecting a node](#select---selecting-a-node)
29+
- [select - selects a node](#select---selects-a-node)
2830
- [isSelected - checks whether a node is selected](#isselected---checks-whether-a-node-is-selected)
2931
- [collapse - collapses a node](#collapse---collapses-a-node)
3032
- [isCollapsed - check whether a node is collapsed](#iscollapsed---check-whether-a-node-is-collapsed)
3133
- [expand - expands a node](#expand---expands-a-node)
32-
- [isExpanded - checks wheather a node is expanded](#isexpanded---checks-wheather-a-node-is-expanded)
34+
- [isExpanded - checks whether a node is expanded](#isexpanded---checks-whether-a-node-is-expanded)
3335
- [rename - renames a node (changes its value underneath)](#rename---renames-a-node-changes-its-value-underneath)
36+
- [startRenaming - changes the node template so that text input appears and lets a user type a new name](#startrenaming---changes-the-node-template-so-that-text-input-appears-and-lets-a-user-type-a-new-name)
3437
- [remove - removes a node from the tree](#remove---removes-a-node-from-the-tree)
3538
- [addChild - creates a new child node](#addchild---creates-a-new-child-node)
3639
- [changeNodeId - changes node's id](#changenodeid---changes-nodes-id)
37-
- [reloadChildren - load async children once more](#reloadchildren---load-async-children-once-more)
40+
- [reloadChildren - loads async children once more](#reloadchildren---loads-async-children-once-more)
3841
- [setChildren - changes children of a node;](#setchildren---changes-children-of-a-node)
3942
- [SystemJS](#systemjs)
4043
- [Changes that should be taken into account in order to migrate from __ng2-tree V1__ to __ng2-tree V2__](#changes-that-should-be-taken-into-account-in-order-to-migrate-from-__ng2-tree-v1__-to-__ng2-tree-v2__)
@@ -154,7 +157,8 @@ Here is the fully stuffed *tree* tag that you can use in your templates:
154157
(nodeMoved)="handleMoved($event)"
155158
(nodeCreated)="handleCreated($event)"
156159
(nodeExpanded)="handleExpanded($event)"
157-
(nodeCollapsed)="handleCollapsed($event)">
160+
(nodeCollapsed)="handleCollapsed($event)"
161+
(loadNextLevel)="handleNextLevel($event)">
158162
</tree>
159163
```
160164

@@ -286,6 +290,27 @@ Another worth noting thing is `loadChildren`. This function on `TreeModel` allow
286290
Node that defines this function is collapsed by default. At the moment of clicking 'Expand' arrow, it starts loading its children by calling given function.
287291
If `loadChildren` function is given to the node - `children` property is ignored. For more details - have a look at the [Demo](#eyes-demo).
288292

293+
#### Load children using ngrx (or any redux-like library)
294+
295+
You can also load children by changing the tree state using ngrx.
296+
The tree can emit an appropriate event notifying you to dispatch a new action in order to load the branch's children.
297+
298+
To enable this feature you should set the ```TreeModel.emitLoadNextLevel``` property to true:
299+
300+
```typscript
301+
const model: TreeModel = {
302+
emitLoadNextLevel : true
303+
}
304+
```
305+
306+
Now on the first time the node is expanded a __LoadNextLevelEvent__ will be fired (via the __loadNextLevel__ EventEmitter in the tree) containing the node that requested a next level (its children) loading.
307+
308+
In your code make sure you change the tree state and add the children to the model.
309+
310+
In addition the regular __NodeExpanded__ event will be fired.
311+
312+
__NOTICE__: if both ```emitLoadNextLevel``` and ```loadChildren``` are provided, the tree will ignore the ```emitLoadNextLevel``` and the ```LoadNextLevelEvent``` won't be fired.
313+
289314
#### Configure node via TreeModelSettings
290315

291316
Apart from that `TreeModel` interface has an optional field called `settings` of type `TreeModelSettings`.
@@ -352,10 +377,6 @@ Also in the next section, you'll be reading about events generated by the `ng2-t
352377

353378
### events (nodeMoved, nodeSelected, nodeRenamed, nodeRemoved, nodeCreated, nodeExpanded, nodeCollapsed)
354379

355-
Here is the diagram that shows tree events' hierarchy
356-
357-
![tree events hierarchy](media/tree-events-hierarchy.png)
358-
359380
`NodeEvent` is the root of the tree events' hierarchy. It defines property `node` that contains a receiver of the event action (`node` is an instance of the `Tree` class).
360381

361382
`NodeDestructiveEvent` is the parent for all events that cause changes to the structure of the tree or to the node's value.
@@ -490,6 +511,24 @@ You can subscribe to `NodeCollapsedEvent` by attaching listener to `(nodeCollaps
490511
{node: <Tree>{...}}
491512
```
492513

514+
#### LoadNextLevelEvent
515+
516+
You can subscribe to `LoadNextLevelEvent` by attaching a listener to `(loadNextLevel)` attribute.
517+
Relevant for loading children via ngrx (or any redux-inspired library).
518+
519+
```html
520+
<tree
521+
[tree]="tree"
522+
(loadNextLevel)="handleNextLevel($event)">
523+
</tree>
524+
```
525+
526+
`LoadNextLevelEvent` has a `node` property of the type `Tree`, which contains a node for which next level (its children) should be loaded.
527+
528+
```typescript
529+
{node: <Tree>{...}}
530+
```
531+
493532
## :gun: Controller
494533
First of all you should know how to get a controller of a particular node. You can get a controller of a node only if you set an id property of a node. For example, your tree structure should look like:
495534

@@ -625,6 +664,14 @@ oopNodeController.rename('new value');
625664

626665
This method accepts a string and sets it as a node's new value, this action also fires rename event.
627666

667+
#### startRenaming - changes the node template so that text input appears and lets a user type a new name
668+
669+
```typescript
670+
oopNodeController.startRenaming();
671+
```
672+
673+
After the user entered the new name a rename event will be fired.
674+
628675
#### remove - removes a node from the tree
629676

630677
```typescript

0 commit comments

Comments
 (0)