From 5c41d1b80a36ac63d941284bf8c84f027e59d501 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Mon, 16 Oct 2017 10:33:22 +0300 Subject: [PATCH] EphemeralCommit 3 --- lib/query-controller.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/query-controller.js b/lib/query-controller.js index 554674c..e715570 100644 --- a/lib/query-controller.js +++ b/lib/query-controller.js @@ -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); } /** @@ -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); }