frontend/.pnpm-store/v3/files/8c/0bd3002a2d75084ac218dbc247d810b5c338b84f04bb064483867f312a23078bcf84bd3f70665f0827efb9c6a90213eda8ee02b3c417d1a3780712db1ac891

25 lines
748 B
Plaintext

import { from, of } from 'rxjs';
import runAsync from 'run-async';
/**
* 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
*/
export const fetchAsyncQuestionProperty = function (question, prop, answers) {
if (typeof question[prop] !== 'function') {
return of(question);
}
return from(
runAsync(question[prop])(answers).then((value) => {
question[prop] = value;
return question;
})
);
};