From c44a3cbe3a3c1ca3252c53ac2486d38663d7584a Mon Sep 17 00:00:00 2001 From: Hiroki Terashima Date: Tue, 7 Nov 2023 13:08:41 -0800 Subject: [PATCH] refactor(NodeService): evaluateTransitionLogic() Remove null checks Consolidate cases --- src/assets/wise5/services/nodeService.ts | 34 +++++++----------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/assets/wise5/services/nodeService.ts b/src/assets/wise5/services/nodeService.ts index 4a4d3f3f47d..800a3935864 100644 --- a/src/assets/wise5/services/nodeService.ts +++ b/src/assets/wise5/services/nodeService.ts @@ -299,33 +299,19 @@ export class NodeService { /** * Evaluate the transition logic for the current node and create branch - * path taken events if necessary. + * path taken event if necessary. */ evaluateTransitionLogic(): void { - const currentNode: any = this.DataService.getCurrentNode(); - const nodeId = currentNode.id; - const transitionLogic = currentNode.transitionLogic; - if (transitionLogic != null) { - let alreadyBranched = false; - const events = this.DataService.getBranchPathTakenEventsByNodeId(currentNode.id); - if (events.length > 0) { - alreadyBranched = true; - } - if (alreadyBranched) { - if (transitionLogic.canChangePath) { - this.chooseTransition(nodeId, transitionLogic).then((transition) => { - if (transition != null) { - this.createBranchPathTakenEvent(currentNode.id, transition.to); - } - }); + const currentNode = this.ProjectService.getNode(this.DataService.getCurrentNodeId()); + const transitionLogic = currentNode.getTransitionLogic(); + const branchEvents = this.DataService.getBranchPathTakenEventsByNodeId(currentNode.id); + const alreadyBranched = branchEvents.length > 0; + if ((alreadyBranched && transitionLogic.canChangePath) || !alreadyBranched) { + this.chooseTransition(currentNode.id, transitionLogic).then((transition) => { + if (transition != null) { + this.createBranchPathTakenEvent(currentNode.id, transition.to); } - } else { - this.chooseTransition(nodeId, transitionLogic).then((transition) => { - if (transition != null) { - this.createBranchPathTakenEvent(currentNode.id, transition.to); - } - }); - } + }); } }