From 37374105636d1fe4f2f2f1127d9672bb8eb82300 Mon Sep 17 00:00:00 2001 From: Thomas Nordquist Date: Wed, 17 Jul 2019 09:17:46 +0200 Subject: [PATCH] Refactor TreeNode model --- backend/src/Model/TreeNode.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/src/Model/TreeNode.ts b/backend/src/Model/TreeNode.ts index c2b6c11..ce21a0b 100644 --- a/backend/src/Model/TreeNode.ts +++ b/backend/src/Model/TreeNode.ts @@ -52,9 +52,12 @@ export class TreeNode { return this.sourceEdge ? this.sourceEdge.source || undefined : undefined } + private hasMessage() { + return this.message && this.message.value && this.message.value.length !== 0 + } + private isTopicEmptyLeaf() { - const hasNoMessage = !this.message || !this.message.value || this.message.value.length === 0 - return hasNoMessage && this.isLeaf() + return !this.hasMessage() && this.isLeaf() } private isLeaf() { @@ -221,7 +224,7 @@ export class TreeNode { if (this.cachedChildTopicCount === undefined) { this.cachedChildTopicCount = this.edgeArray .map(e => e.target.childTopicCount()) - .reduce((a, b) => a + b, this.edgeArray.length === 0 ? 1 : 0) + .reduce((a, b) => a + b, this.hasMessage() ? 1 : 0) } return this.cachedChildTopicCount as number