[ARVADOS-WORKBENCH2] updated: 2.1.0-159-gd9438b97

Git user git at public.arvados.org
Fri Jan 15 17:19:41 UTC 2021


Summary of changes:
 src/views-components/tree-picker/tree-picker.ts | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

       via  d9438b97a2ca16ee35a93e54a5bdd1312ea65fbe (commit)
      from  c859c9d9325e2ed86d5d7b067e1209e73ee81251 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit d9438b97a2ca16ee35a93e54a5bdd1312ea65fbe
Author: Daniel Kutyła <daniel.kutyla at contractors.roche.com>
Date:   Fri Jan 15 18:18:50 2021 +0100

    17256: Code optimisation
    
    Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla at contractors.roche.com>

diff --git a/src/views-components/tree-picker/tree-picker.ts b/src/views-components/tree-picker/tree-picker.ts
index 9bb52dee..822fdcf2 100644
--- a/src/views-components/tree-picker/tree-picker.ts
+++ b/src/views-components/tree-picker/tree-picker.ts
@@ -18,22 +18,18 @@ export interface TreePickerProps<T> {
     toggleItemSelection: Callback<T>;
 }
 
-const flatTree = (depth: number, items?: any): [] => {
+const flatTree = (itemsIdMap: Map<string, any>, depth: number, items?: any): [] => {
     return items ? items
-        .map(addToItemsIdMap)
-        .reduce((prev: any, next: any) => {
+        .map((item: any) => addToItemsIdMap(item, itemsIdMap))
+        .reduce((prev: Array<any>, next: any) => {
             const { items } = next;
-
-            return [
-                ...prev,
-                { ...next, depth },
-                ...(next.open ? flatTree(depth + 1, items) : []),
-            ];
+            prev.push({ ...next, depth });
+            prev.push(...(next.open ? flatTree(itemsIdMap, depth + 1, items) : []));
+            return prev;
         }, []) : [];
 };
 
-const itemsIdMap = new Map();
-const addToItemsIdMap = <T>(item: TreeItem<T>) => {
+const addToItemsIdMap = <T>(item: TreeItem<T>, itemsIdMap: Map<string, TreeItem<T>>) => {
     itemsIdMap[item.id] = item;
     return item;
 };
@@ -42,6 +38,7 @@ const memoizedMapStateToProps = () => {
     let prevTree: Ttree<any>;
     let mappedProps: Pick<TreeProps<any>, 'items' | 'disableRipple' | 'itemsMap'>;
     return <T>(state: RootState, props: TreePickerProps<T>): Pick<TreeProps<T>, 'items' | 'disableRipple' | 'itemsMap'> => {
+        const itemsIdMap: Map<string, TreeItem<T>> = new Map();
         const tree = state.treePicker[props.pickerId] || createTree();
         if (tree !== prevTree) {
             prevTree = tree;
@@ -49,11 +46,11 @@ const memoizedMapStateToProps = () => {
                 disableRipple: true,
                 items: getNodeChildrenIds('')(tree)
                     .map(treePickerToTreeItems(tree))
-                    .map(addToItemsIdMap)
+                    .map(item => addToItemsIdMap(item, itemsIdMap))
                     .map(parentItem => ({
                         ...parentItem,
                         flatTree: true,
-                        items: flatTree(2, parentItem.items || []),
+                        items: flatTree(itemsIdMap, 2, parentItem.items || []),
                     })),
                 itemsMap: itemsIdMap,
             };

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list