diff --git a/app/index.html b/app/index.html index a015f52..23522d9 100644 --- a/app/index.html +++ b/app/index.html @@ -60,7 +60,6 @@ } -
diff --git a/app/src/actions/Settings.ts b/app/src/actions/Settings.ts index 3216dba..5a4952c 100644 --- a/app/src/actions/Settings.ts +++ b/app/src/actions/Settings.ts @@ -53,7 +53,7 @@ export const filterTopics = (filterStr: string) => (dispatch: Dispatch, get return Boolean(messageMatches) } - const resultTree = tree.leafes() + const resultTree = tree.childTopics() .filter(nodeFilter) .map((node) => { const clone = node.unconnectedClone() diff --git a/app/src/components/Sidebar/NodeStats.tsx b/app/src/components/Sidebar/NodeStats.tsx index 5acac1c..6858a81 100644 --- a/app/src/components/Sidebar/NodeStats.tsx +++ b/app/src/components/Sidebar/NodeStats.tsx @@ -18,7 +18,7 @@ class NodeStats extends React.Component { return (
Messages: #{node.messages} - Subtopics: {node.leafCount()} + Subtopics: {node.childTopicCount()} Messages Subtopics: #{node.leafMessageCount()}
) diff --git a/app/src/components/Tree/Tree.tsx b/app/src/components/Tree/Tree.tsx index e51b81f..f792f35 100644 --- a/app/src/components/Tree/Tree.tsx +++ b/app/src/components/Tree/Tree.tsx @@ -90,7 +90,7 @@ class Tree extends React.Component { animateChages={true} isRoot={true} treeNode={tree} - name="/" + name={'"root"'} lastUpdate={tree.lastUpdate} collapsed={false} performanceCallback={this.performanceCallback} diff --git a/app/src/components/Tree/TreeNodeSubnodes.tsx b/app/src/components/Tree/TreeNodeSubnodes.tsx index 8caee35..85240ad 100644 --- a/app/src/components/Tree/TreeNodeSubnodes.tsx +++ b/app/src/components/Tree/TreeNodeSubnodes.tsx @@ -42,7 +42,7 @@ class TreeNodeSubnodes extends React.Component { nodes = nodes.sort((a, b) => b.leafMessageCount() - a.leafMessageCount()) } if (topicOrder === TopicOrder.topics) { - nodes = nodes.sort((a, b) => b.leafCount() - a.leafCount()) + nodes = nodes.sort((a, b) => b.childTopicCount() - a.childTopicCount()) } return nodes diff --git a/app/src/components/Tree/TreeNodeTitle.tsx b/app/src/components/Tree/TreeNodeTitle.tsx index 89b68b9..00ab003 100644 --- a/app/src/components/Tree/TreeNodeTitle.tsx +++ b/app/src/components/Tree/TreeNodeTitle.tsx @@ -84,7 +84,7 @@ class TreeNodeTitle extends React.Component { } const messages = this.props.treeNode.leafMessageCount() - return ({this.props.treeNode.leafCount()} nodes, {messages} messages) + return ({this.props.treeNode.childTopicCount()} topics, {messages} messages) } } diff --git a/backend/src/Model/TreeNode.ts b/backend/src/Model/TreeNode.ts index 9b9e240..5aaeb3e 100644 --- a/backend/src/Model/TreeNode.ts +++ b/backend/src/Model/TreeNode.ts @@ -16,9 +16,10 @@ export class TreeNode { public onMessage = new EventDispatcher(this) public isTree = false - private cachedLeafes?: TreeNode[] + private cachedPath?: string + private cachedChildTopics?: TreeNode[] private cachedLeafMessageCount?: number - private cachedLeafCount?: number + private cachedChildTopicCount?: number public unconnectedClone() { const node = new TreeNode() @@ -39,8 +40,8 @@ export class TreeNode { message && this.setMessage(message) this.onMerge.subscribe(() => { - this.cachedLeafes = undefined - this.cachedLeafCount = undefined + this.cachedChildTopics = undefined + this.cachedChildTopicCount = undefined this.cachedLeafMessageCount = undefined this.lastUpdate = Date.now() }) @@ -67,10 +68,14 @@ export class TreeNode { } public path(): string { - return this.branch() - .map(node => (node.sourceEdge && node.sourceEdge.name)) - .filter(name => name !== undefined) - .join('/') + if (!this.cachedPath) { + return this.branch() + .map(node => (node.sourceEdge && node.sourceEdge.name)) + .filter(name => name !== undefined) + .join('/') + } + + return this.cachedPath } private previous(): TreeNode | undefined { @@ -117,30 +122,30 @@ export class TreeNode { return this.cachedLeafMessageCount } - public leafCount(): number { - if (this.cachedLeafCount === undefined) { - this.cachedLeafCount = this.edgeArray - .map(e => e.target.leafCount()) + public childTopicCount(): number { + if (this.cachedChildTopicCount === undefined) { + this.cachedChildTopicCount = this.edgeArray + .map(e => e.target.childTopicCount()) .reduce((a, b) => a + b, this.edgeArray.length === 0 ? 1 : 0) } - return this.cachedLeafCount + return this.cachedChildTopicCount } public edgeCount(): number { return this.edgeArray.length } - public leafes(): TreeNode[] { - if (this.cachedLeafes === undefined) { + public childTopics(): TreeNode[] { + if (this.cachedChildTopics === undefined) { const initialValue = this.message && this.message.value ? [this] : [] - this.cachedLeafes = this.edgeArray - .map(e => e.target.leafes()) + this.cachedChildTopics = this.edgeArray + .map(e => e.target.childTopics()) .reduce((a, b) => a.concat(b), initialValue) } - return this.cachedLeafes + return this.cachedChildTopics } private mergeEdges(node: TreeNode) {