Skip to content

Commit

Permalink
feat(core): update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-antonenka-sap committed Sep 4, 2023
1 parent 506bf90 commit 3088f24
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ Add/Insert/Delete - quick helper methods:
addItems(items, itemChildren: { $0.subitems }, to: listTreeDataSource)
```

Fold (inorder traversal + map into final result):
Use case: changes were made and we need final tree. FO
```
let folded = listTreeDataSource.fold(NodeTestItem.init) { item, subitems in
NodeTestItem(identifier: item.identifier, title: item.title, subitems: subitems)
}
Or Fold with Identity (when element already hierarchical item):
let folded = sut.fold({ $0 }) { root, _ in root }
```

Add/Insert/Delete/Move - More grannular control:
```
// Append:
Expand All @@ -63,8 +74,9 @@ listTreeDataSource.delete([itemToDelete])
// Move:
// E.g. user drags `existingNode` into `newParent` subitems with 0 index.
// existingNode = listTreeDataSource.items[sourceIdx]
// existingNode = listTreeDataSource.items[sourceIdx];
// newParent = listTreeDataSource.items[dropParentIdx];
// toIndex = drop index in newParent;
listTreeDataSource.move(existingNode, toIndex: 0, inParent: newParent)
// NOTE: Reload data source at the end of changes.
Expand Down

0 comments on commit 3088f24

Please sign in to comment.