2022-01-21 08:28:41 +00:00
|
|
|
'use strict';
|
2022-04-07 07:06:43 +00:00
|
|
|
const { from, of } = require('rxjs');
|
|
|
|
const runAsync = require('run-async');
|
2022-01-21 08:28:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve a question property value if it is passed as a function.
|
|
|
|
* This method will overwrite the property on the question object with the received value.
|
|
|
|
* @param {Object} question - Question object
|
|
|
|
* @param {String} prop - Property to fetch name
|
|
|
|
* @param {Object} answers - Answers object
|
|
|
|
* @return {Rx.Observable} - Observable emitting once value is known
|
|
|
|
*/
|
|
|
|
|
2022-04-07 07:06:43 +00:00
|
|
|
exports.fetchAsyncQuestionProperty = function (question, prop, answers) {
|
|
|
|
if (typeof question[prop] !== 'function') {
|
2022-01-21 08:28:41 +00:00
|
|
|
return of(question);
|
|
|
|
}
|
|
|
|
|
|
|
|
return from(
|
2022-04-07 07:06:43 +00:00
|
|
|
runAsync(question[prop])(answers).then((value) => {
|
2022-01-21 08:28:41 +00:00
|
|
|
question[prop] = value;
|
|
|
|
return question;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
};
|