Skip to content

Commit

Permalink
EphemeralCommit 3
Browse files Browse the repository at this point in the history
  • Loading branch information
GochoMugo committed Oct 16, 2017
1 parent 0280041 commit 5c41d1b
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/query-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,16 @@ class QueryController {

/**
* Retrieve an answer.
* If `name` is omitted, it returns answer for the current query.
* If `name` is omitted/falsey, it returns answer for the current query.
* To use `defaultValue`, `name` must be specified.
* @param {String} [name] Name of query
* @param {*} [defaultValue] Default value
* @return {*} value
* @throws {QueryNotFoundError} If the current query is not found.
*/
getAnswer(name) {
getAnswer(name, defaultValue) {
if (!name) name = this._getCurrentQuery().name;
return _.get(this.session.answers, name);
return _.get(this.session.answers, name, defaultValue);
}

/**
Expand Down Expand Up @@ -286,15 +288,15 @@ class QueryController {
const cs = []; // structured choices; for question
const objs = [question]; // objs requiring i18n; interface { text }
for (let choice of choices) {
const c = {
id: choice.id || choice,
text: choice.text || choice,
};
if (typeof choice.when === "function") {
if (!choice.when.call(this)) {
continue;
}
}
const c = {
id: choice.id || choice,
text: choice.text || choice,
};
cs.push(c);
objs.push(c);
}
Expand Down

0 comments on commit 5c41d1b

Please sign in to comment.