UNPKG

819 BJavaScriptView Raw
1'use strict';
2const _ = {
3 isFunction: require('lodash/isFunction'),
4};
5const { from, of } = require('rxjs');
6const runAsync = require('run-async');
7
8/**
9 * Resolve a question property value if it is passed as a function.
10 * This method will overwrite the property on the question object with the received value.
11 * @param {Object} question - Question object
12 * @param {String} prop - Property to fetch name
13 * @param {Object} answers - Answers object
14 * @return {Rx.Observable} - Observable emitting once value is known
15 */
16
17exports.fetchAsyncQuestionProperty = function (question, prop, answers) {
18 if (!_.isFunction(question[prop])) {
19 return of(question);
20 }
21
22 return from(
23 runAsync(question[prop])(answers).then((value) => {
24 question[prop] = value;
25 return question;
26 })
27 );
28};