From 571d7def7c9f1f9042316cab8062601a436a8fee Mon Sep 17 00:00:00 2001 From: Andreas Holstenson Date: Sat, 5 Jan 2019 15:35:08 +0100 Subject: [PATCH] refactor(graph): Encounter.branchInto(nodes) instead of .next(nodes) --- src/graph/matching/encounter.js | 22 +++++++++++++++------- src/graph/sub.js | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/graph/matching/encounter.js b/src/graph/matching/encounter.js index bff553e..5ae4aa3 100644 --- a/src/graph/matching/encounter.js +++ b/src/graph/matching/encounter.js @@ -78,12 +78,7 @@ export default class Encounter { * For every outgoing node: * - Run the match method, checking if it matches */ - next(nodes, score, consumedTokens, data) { - if(! Array.isArray(nodes)) { - // If the first argument is not a list of nodes assume outgoing - return this.next(this.outgoing, nodes, score, consumedTokens); - } - + next(score, consumedTokens, data) { let nextIndex = this.currentIndex + (consumedTokens || 0); const nextScore = this.currentScore + (score || 0); @@ -152,6 +147,7 @@ export default class Encounter { } }; + const nodes = this.outgoing; let promise = Promise.resolve(); for(let i=0; i this.outgoing = outgoing); + } + branchWithOnMatch(newOnMatch, func) { const onMatch = this.onMatch; const currentDataDepth = this.currentDataDepth; diff --git a/src/graph/sub.js b/src/graph/sub.js index 959985d..44b0ff2 100644 --- a/src/graph/sub.js +++ b/src/graph/sub.js @@ -152,7 +152,7 @@ export default class SubNode extends Node { encounter.supportsFuzzy = this.supportsFuzzy; encounter.skipPunctuation = this.skipPunctuation; - return encounter.next(this.roots); + return encounter.branchInto(this.roots); }).then(() => { // Switch back to previous supported values encounter.supportsPartial = supportsPartial;