Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
819 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict';
|
---|
| 2 | const _ = {
|
---|
| 3 | isFunction: require('lodash/isFunction'),
|
---|
| 4 | };
|
---|
| 5 | const { from, of } = require('rxjs');
|
---|
| 6 | const 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 |
|
---|
| 17 | exports.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 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.