I am new to React, Redux and ImmutableJS and have encountered some performance issues.
I have a large tree-like data structure that I now store as a flat list in this structure:
new Map({ 1: new Node({ id: 1, text: 'Root', children: [2,3] }), 2: new Node({ id: 2, text: 'Child 1', children: [4] }), 3: new Node({ id: 3, text: 'Child 2', children: [] }), 4: new Node({ id: 4, text: 'Child of child 1', children: [] }) });
Structuring it as a flat list simplifies updating nodes, I find that the interaction becomes sluggish as the tree grows. Interaction includes the ability to select one or more nodes, switch the visibility of their child nodes, update text, etc. It seems that the key reason for the sluggish interface is that the entire tree is redrawn for each interaction.
I want to use shouldComponentUpdate so that when updating node 3, nodes 2 and 4 are not updated. It would be easy if the data was saved as a tree (I could just check if this.props !== nextProps ), but since the data is stored in a flat list, the verification will be much more complicated.
How do I store data and use shouldComponentUpdate (or other methods) to support a smooth interface with hundreds or thousands of tree nodes?
Edit
I connected the storage at the top level, and then I have to transfer the entire storage to subcomponents.
My structure:
<NodeTree> <NodeBranch> <Node>{{text}}</Node> <NodeTree>...</NodeTree> </NodeBranch> <NodeBranch> <Node>{{text}}</Node> <NodeTree>...</NodeTree> </NodeBranch> ... </NodeTree>
<Node> can do a simple check with shouldComponentUpdate to see if the title has changed, but I don't have a similar solution to use in <NodeTree> or <NodeBranch> , given the recursive nature of the tree.
It seems like the best solution (thanks to @Dan Abramov) would be to connect each <NodeBranch> , but just a top-level connection. I will spend it tonight.