Skip to content

Commit

Permalink
fix issue where local vars didnt update
Browse files Browse the repository at this point in the history
  • Loading branch information
terkelg committed Mar 9, 2018
1 parent 2ad8dc0 commit 225818b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 7 additions & 7 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ const { prompt } = require('./lib');
message: 'Can you confirm?'
},
{
type: 'list',
name: 'keywords',
message: 'Enter keywords'
},
{
type: 'toggle',
type: prev => prev && 'toggle',
name: 'confirmtoggle',
message: 'Can you confirm?',
message: 'Can you confirm again?',
active: 'yes',
inactive: 'no'
},
{
type: 'list',
name: 'keywords',
message: 'Enter keywords'
},
{
type: 'select',
name: 'color',
Expand Down
8 changes: 6 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const noop = () => {};
async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
const answers = {};
questions = [].concat(questions);
let answer, question, quit, name, type, key;
let answer, question, quit, name, type;
let MAP = prompt._map || {};

for (question of questions) {
Expand All @@ -30,12 +30,16 @@ async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
}

// if property is a function, invoke it unless it's ignored
for (key in question) {
for (let key in question) {
if (ignore.includes(key)) continue;
let value = question[key];
question[key] = typeof value === 'function' ? await value(answer, { ...answers }, question) : value;
}

// update vars in case they changed
({ name, type } = question);


// skip if type is a falsy value
if (!type) continue;

Expand Down

0 comments on commit 225818b

Please sign in to comment.