Skip to content

Commit

Permalink
Finished adding #107
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Walter committed Oct 26, 2019
1 parent bc0beec commit 0063e41
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
39 changes: 33 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,42 @@ decisionTree.current() /* => {

### Instance methods

next Continues to the next node
prev Goes back to the previous node in the path
pathKeys Returns an array with node keys in order of the path
```js
// Set a value (selected option / answer) for a question.
decisionTree.set(key, value)

// Return the current node (the last node in the path).
decisionTree.current()

// Append the given node to the path, making it the current node.
decisionTree.goToNode(node)

// Determine the next node to move to by handling the selected option's leadsTo
// property/method.
decisionTree.getNodeFromLeadsTo(currentNode, selectedOption)

// Continue to the next node.
decisionTree.next()

// Go back to the previous node in the path.
decisionTree.prev()

// Return the branch/path as an array of ordered node keys.
decisionTree.pathKeys()
```

### Errors

NoChildrenError
NoLeadToError
NoParenError
```js
import {
// There are no children to navigate to when calling next.
NoChildrenError,
// The next node to navigate to can't be determined when calling next.
NoLeadsToError,
// There is no parent to navigate to when calling prev.
NoParentError
} from '@ianwalter/decision-tree'
```

## License

Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class NoChildrenError extends BaseError {
}
}

class NoLeadToError extends BaseError {
class NoLeadsToError extends BaseError {
constructor (key, option) {
super('Cannot determine which child to move to', { key, option })
}
Expand Down Expand Up @@ -78,7 +78,7 @@ class DecisionTree {
}

// Throw an error if the next node to move to can't be determined.
throw new NoLeadToError(selectedOptionKey, selectedOption)
throw new NoLeadsToError(selectedOptionKey, selectedOption)
}

prev () {
Expand All @@ -96,7 +96,7 @@ class DecisionTree {

export {
NoChildrenError,
NoLeadToError,
NoLeadsToError,
NoParentError,
DecisionTree
}

0 comments on commit 0063e41

Please sign in to comment.