[ARVADOS-WORKBENCH2] updated: 1.1.4-469-gbe2f555

Git user git at public.curoverse.com
Wed Aug 1 05:01:43 EDT 2018


Summary of changes:
 .../collection-panel-files.ts                      | 25 ++++++++++++++++------
 1 file changed, 18 insertions(+), 7 deletions(-)

       via  be2f555375b863b5171cebe6375acb4c0267e818 (commit)
      from  b9b782c0259f06f4ae743389403a6321b84cda1a (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 be2f555375b863b5171cebe6375acb4c0267e818
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Wed Aug 1 10:22:59 2018 +0200

    Apply simple memoization in state mapping function
    
    Feature #13855
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/views-components/collection-panel-files/collection-panel-files.ts b/src/views-components/collection-panel-files/collection-panel-files.ts
index 0542ce9..09fdd67 100644
--- a/src/views-components/collection-panel-files/collection-panel-files.ts
+++ b/src/views-components/collection-panel-files/collection-panel-files.ts
@@ -6,18 +6,29 @@ import { connect } from "react-redux";
 import { CollectionPanelFiles as Component, CollectionPanelFilesProps } from "../../components/collection-panel-files/collection-panel-files";
 import { RootState } from "../../store/store";
 import { TreeItemStatus, TreeItem } from "../../components/tree/tree";
-import { CollectionPanelItem } from "../../store/collection-panel/collection-panel-files/collection-panel-files-state";
+import { CollectionPanelItem, CollectionPanelFilesState } from "../../store/collection-panel/collection-panel-files/collection-panel-files-state";
 import { FileTreeData } from "../../components/file-tree/file-tree-data";
 import { Dispatch } from "redux";
 import { collectionPanelFilesAction } from "../../store/collection-panel/collection-panel-files/collection-panel-files-actions";
 import { contextMenuActions } from "../../store/context-menu/context-menu-actions";
 import { ContextMenuKind } from "../context-menu/context-menu";
 
-const mapStateToProps = (state: RootState): Pick<CollectionPanelFilesProps, "items"> => ({
-    items: state.collectionPanelFiles
-        .filter(item => item.parentId === '')
-        .map(collectionItemToTreeItem(state.collectionPanelFiles))
-});
+const mapStateToProps = () => {
+    let lastState: CollectionPanelFilesState;
+    let lastTree: Array<TreeItem<FileTreeData>>;
+
+    return (state: RootState): Pick<CollectionPanelFilesProps, "items"> => {
+        if (lastState !== state.collectionPanelFiles) {
+            lastState = state.collectionPanelFiles;
+            lastTree = state.collectionPanelFiles
+                .filter(item => item.parentId === '')
+                .map(collectionItemToTreeItem(state.collectionPanelFiles));
+        }
+        return {
+            items: lastTree
+        };
+    };
+};
 
 const mapDispatchToProps = (dispatch: Dispatch): Pick<CollectionPanelFilesProps, 'onCollapseToggle' | 'onSelectionToggle' | 'onItemMenuOpen' | 'onOptionsMenuOpen'> => ({
     onCollapseToggle: (id) => {
@@ -41,7 +52,7 @@ const mapDispatchToProps = (dispatch: Dispatch): Pick<CollectionPanelFilesProps,
 });
 
 
-export const CollectionPanelFiles = connect(mapStateToProps, mapDispatchToProps)(Component);
+export const CollectionPanelFiles = connect(mapStateToProps(), mapDispatchToProps)(Component);
 
 const collectionItemToTreeItem = (items: CollectionPanelItem[]) => (item: CollectionPanelItem): TreeItem<FileTreeData> => {
     return {

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list