Documentation for update functions
The updateTree function does not have an example on the docs. We need more information on how it works.
The docs with examples are underway, but I'll try to give a quick answer here until then.
function updateTree(
array: Array<TreeItem>,
updateCallback: (item?: TreeItem, index?: number) => TreeItem,
itemFilter?: (item?: TreeItem, index?: number) => boolean,
childrenField?: string,
removeFilter?: (item?: TreeItem, index?: number) => boolean,
): Array<TreeItem>;
updateTree is normally used with tree grids and allows us to make safe updates on the tree in a systematic way. Here is a common workflow:
// get the tree from the store
let tree = this.store.get("tree");
// create updated copy
let updatedTree = updateTree(tree, updateCallback[, ...]);
// save the updated copy to the store
this.store.set("tree", updatedTree);
updateTree is a pure function, meaning it takes the tree, makes some updates and returns an updated copy of the tree. The original tree is left unchanged.
-
arrayis the tree structure, that is an array of objects/tree items with their children subarrays stored under thechildrenField, which is by defaultchildren. -
updateCallbackis the update function that will be executed on each tree item that passes the filter, if there is one set.updateCallbacktakes two arguments,itemandindex, and returns an updated copy of the tree item. This should be a pure funciton that makes no changes on the originalitem. -
itemFilteris a predicate function, meaning, it receives the tree item and its index as arguments, and returnstrueorfalse. Only items for whichitemFilterreturnstruewill get updated. -
childrenFieldis the name of the property under which child items are stored. By default, it'schildren. -
removeFilteris another predicate function that receives tree item and its index as arguments and returns eithertrueorfalse. Each tree item for whichremoveFilterreturnstrueis removed from the updated tree.
The array and updateCallback parameters are obligatory, whereas itemFilter, childrenField and removeFilter are optional.
Hope this helps. Let me know if you have any other qustions. We'll leave the issue open until the docs are complete.
Thanks, that is very helpful!